Question: How will you print your name in Java?

How can I write my name in Java?

Example of nextLine() method

  1. import java.util.*;
  2. class UserInputDemo1.
  3. {
  4. public static void main(String[] args)
  5. {
  6. Scanner sc= new Scanner(System.in); //System.in is a standard input stream.
  7. System.out.print(“Enter a string: “);
  8. String str= sc.nextLine(); //reads string.

How do I print 10 times a word in Java?

Java – How to print a name 10 times?

  1. Looping. 1.1 For loop. …
  2. Read and Print. This example will read input from the console and print it ten times. …
  3. Recursion. This example will use a recursion loop. …
  4. No Loop , No Recursion. …
  5. Char + String and Replace. …
  6. Java 8 String Join. …
  7. Java 8 IntStream.range. …
  8. Java 11 Repeat.

How do you repeat a name in Java?

Here is the shortest version (Java 1.5+ required): repeated = new String(new char[n]). replace(“

THIS IS IMPORTANT:  You asked: How do you reuse an object in Java?
Categories BD