+ 1

How do I print my name 1000 times in Java without looping?

Question about a program.

19th Jul 2018, 11:35 AM
Vishal Kumar
10 Antworten
+ 22
System.out.print( String.format("%1000s", " ") .replace(" ", "*** My Name!:) ***\n") );
20th Jul 2018, 8:36 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 11
Type System.out.println(name); 1000 times
19th Jul 2018, 11:37 AM
TurtleShell
TurtleShell - avatar
+ 11
voja 😄Great my friend! 🤓🍻 I'm impressed by you work💪 Thank a lot my friend 😉
11th Oct 2019, 11:12 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 8
use a recursive function that will call itself 1000 times, and make the function print your name
19th Jul 2018, 11:38 AM
hinanawi
hinanawi - avatar
+ 5
Hi Danijel Ivanović! Technically, you are using loop, because method replace() contains it (actually, it has 2 while loops). I was impressed by your solution so I had had to check how it works.🧐😁 Still, looks awesome! 👌 Beautiful idea (no surprise, physicists are full of them) !💡👍 https://code.sololearn.com/c8sfev9h1hP9/?ref=app
11th Oct 2019, 7:22 AM
voja
voja - avatar
+ 2
int n =1000; while(n>0){ system.out.println("name"); n--; }
11th Oct 2019, 7:24 AM
Sanjay Soni
Sanjay Soni - avatar
0
TurtleShell i completely agree, yours deserves best answer more than mine
19th Jul 2018, 9:31 PM
hinanawi
hinanawi - avatar
0
o satellite i don't know why, but this isn't the first time i've seen such a question
20th Jul 2018, 3:21 PM
hinanawi
hinanawi - avatar
0
Using the concept of recursion: public class MyClass { private static void printName(int n) { if (--n > 0) { System.out.println("My Name"); printName(n); } } public static void main(String args[]) { printName(1000); } }
6th Jul 2021, 2:59 PM
Kayle Maclou
Kayle Maclou - avatar
- 1
hinanawi answer is good but I personally think mine’s is better
19th Jul 2018, 9:29 PM
TurtleShell
TurtleShell - avatar