Iteration without loop

Ads
 

Iteration without loop

Hi,

Is there any way I can have a line of code iterate a number of times set by the user without having a while loop or any other control statements?

Thanks!

View Answers

October 24, 2011 at 11:19 AM

import java.util.*;
class RepeatString 
{
    public static String repeat(String str, int times){
   return new String(new char[times]).replace("\0", str);
}

    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter no. of times: ");
        int no=input.nextInt();
        String st="Hello World";
        System.out.println(repeat(st+"\n", no));

    }
}

October 25, 2011 at 1:56 AM

Thanks so much!

Ads









Related Tutorials/Questions & Answers:
Iteration without loop
Iteration without loop  Hi, Is there any way I can have a line of code iterate a number of times set by the user without having a while loop or any other control statements? Thanks!   import java.util.*; class
Iteration
of similar tasks is what Iteration is and that too without making any errors. Until...;iteration : It is an expression that increments or decrements the loop control variable...; iteration){ //body of the loop } For example, a sample for loop may appear
Advertisements
Iteration
. Repetition of similar tasks is what Iteration is and that too without making any...;  iteration : It is an expression that increments or decrements the loop...; condition; iteration){ //body of the loop } For example, a sample for loop
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
for loop
for loop  what is for loop   Loops are used for iteration... for a number of times it is finite loop and if repetition is done infinitely it is infinite loop. Java provides several loop structures for iteration. Those
without ;
without ;  can u give me an example of a program without
without ;
without ;  can u give me an example of a program without
loop
loop  what is the difference b/w do while,while and for loop..with example
loop
loop  i want to write my name(inder) through loop in java using star
For loop
For loop  Hi! Please explain the following loop: for(i=0;i<a[j];i++) THANX!!   Please reply as soon as possible
for loop
for loop  how to performs the for loop when 2 inputs given like displays the triangle shape and how to take initial values or declaration values plz explain in detailed ex. 1 12 123 1234
ModuleNotFoundError: No module named 'iteration'
ModuleNotFoundError: No module named 'iteration'  Hi, My Python... 'iteration' How to remove the ModuleNotFoundError: No module named 'iteration' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'iteration'
ModuleNotFoundError: No module named 'iteration'  Hi, My Python... 'iteration' How to remove the ModuleNotFoundError: No module named 'iteration' error? Thanks   Hi, In your python environment you
For Loop
For Loop  Write a program using a for loop that computes the following sum: 1/2 + 2/2 + 3/2 + 4/2 + 5/2 + ... N/2 N will be an integer limit the user enters. This is an example of my upcoming quiz. I need help on knowing
loop
loop  strong textHello can someone help me with this problem,I need to output the following code using a loop the code is as follows with the user inputs in inverted commas,thanks. ENTER CODE(XX to Stop) CODE:"D24" QUANTITY:"2
for loop
for loop  using only two for loop how can print below numbers 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5
for loop
for loop  using only two for loop how can print below numbers 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5
ModuleNotFoundError: No module named 'iteration-utilities'
ModuleNotFoundError: No module named 'iteration-utilities'  Hi, My... named 'iteration-utilities' How to remove the ModuleNotFoundError: No module named 'iteration-utilities' error? Thanks   Hi
JavaScript array iteration
]. The function iteration define a variable space and also include for loop that run... JavaScript array iteration     ... JavaScript array iteration easy to understand. For this we are using JavaScript
FOR Loop In JSP
to be as an iteration of statements. Generally, for loop is used for the known number of iteration before entering the loop. For loop in JSP is used as same as it is used...FOR Loop In JSP In this section we will read about how to use the for loop
foreach Loop
foreach Loop In PHP, for & foreach loop executes code block a specific number of times, or until condition fails. The for Loop The for loop executes... is initialization parameter, condition is used to check condition at every iteration until
Limits of "For loop"
Limits of "For loop"  Hi, How can I check the upper limit and lower limit of 'FOR' loop during unit testing using Junit. Thanks & Regards Ankit
How to write a loop and a while loop
How to write a loop and a while loop  How do I write a 1 loop and a 1 while loop for the example code: public boolean isTheFirstOneBigger (int num1, int num2) { if (num1 > num2) { return true
adding loop
adding loop  Hi I have a program that is not compiling when I add a loop can you help me?The program below is compiling without the loop. >... the loop is: > Blockquote import java.util.*; class Output { public
loop statements
loop statements  write a program that reads from input an interger n and prints the factorial of all numbers between 1 and n
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me

Ads