Contents
show
How can I write my name in Java?
Example of nextLine() method
- import java.util.*;
- class UserInputDemo1.
- {
- public static void main(String[] args)
- {
- Scanner sc= new Scanner(System.in); //System.in is a standard input stream.
- System.out.print(“Enter a string: “);
- String str= sc.nextLine(); //reads string.
How do I print 10 times a word in Java?
Java – How to print a name 10 times?
- Looping. 1.1 For loop. …
- Read and Print. This example will read input from the console and print it ten times. …
- Recursion. This example will use a recursion loop. …
- No Loop , No Recursion. …
- Char + String and Replace. …
- Java 8 String Join. …
- Java 8 IntStream.range. …
- 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(“