Home Answers Viewqa Java-Beginners Iteration without loop

 
 


Dimitri Vasilkov
Iteration without loop
2 Answer(s)      a year and 7 months ago
Posted in : Java Beginners

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!









Related Pages:
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
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
. 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
Iteration
tasks is what Iteration is and that too without making any errors. Until now we... a quick look at the iteration statements which have the ability to loop through... and hence works as a loop terminator.   iteration
Iteration
Iteration  hii, What is an iteration?   hello, The act or an instance of iterating; repetition. time-boxed sequence of activities that results in a release of an executable product
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
Updating variables in a loop? and only printing certain messages after the first iteration?!
Updating variables in a loop? and only printing certain messages after the first iteration?!  I've written a program that reads two values. I... variables update in the loop to be compared to the previous etc
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-each Loop
Java NotesFor-each Loop Purpose The basic for loop was extended in Java 5 to make iteration over arrays and other collections more convenient... the for-in loop. Use it in preference to the standard for loop if applicable
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
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
before the loop is started, usually to initialize an iteration variable. The condition expression is tested before each time the loop is done... Java Notes'for' Loop Purpose The for statement is similar
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
without ;
without ;  can u give me an example of a program without
without ;
without ;  can u give me an example of a program without
PHP Do While Loop
Do-While Loop Function PHP: PHP Do-While loop method is another type of loop which runs at least once, since this loop checks the condition after executing the code within. We generally use Do-While loop  when the iteration must run
For Loop Statement in java 7
/Decrement : It is your iteration part, you can increment or decrement loop variable...For Loop Statement in java 7 In this section, we will discuss about for loop in java 7. This is one type of  loop statement. For Loop Statements
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
Loop
to understand a loop my quesiton are: what du i do wrong in my code since.... (made in blueJ) Class Loop public void loopUpGeneral(int start, int stop... dk  Hi, Please check the for loop once again: for (int i
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
Map Iteration
Java: Map Iteration No direct iteration over Maps -- Get Set of keys or key-value pairs from Mapt Maps do not provide an iterator() method as do Lists... elements in iteration The order of the elements obtained from a Map depends
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
PHP Do While Loop
Do-While Control Structure: Do-While loop is another type of loop which runs at least once, since this loop checks the condition after executing the code within. We generally use Do-While loop  when the iteration must run
String length without using length() method in java
String length without using length() method in java  How to count length of string without using length() method in java?   Here is Example... the number of character into the given string without using the length() method
Loop Control flow enhancement discussion - Java Tutorial
Loop Control flow enhancement discussion 2001-04-28 The Java Specialists... next issue reminding people that Exceptions are not meant to be used as Loop control / Loop Control flow enhancement. I could see someone putting your switch
Java repeat string without using loops
Java repeat string without using loops In this section, you will learn how to repeat string without using for loops. The given example accepts the number of times and iterates the string to the number of times set by the user without
Java: Map Iteration
Java: Map Iteration No direct iteration over Maps -- Get Set of keys or key-value pairs from Mapt Maps do not provide an iterator() method as do Lists... elements in iteration The order of the elements obtained from a Map depends
PHP Object Iteration
PHP Object Iteration: In PHP 5 a new way for objects is introduced to iterate.... All visible (public, protected) properties are used in the iteration. To display... Object Iteration Example: <?php class One{ public $a="A"
PHP While Loop
While Loop in PHP: In programming language we need to use loops for executing... Loop in PHP: While loop checks the condition first and if it is true... the condition to stop, and become infinite loop. While loop is also known as pre-test
how to get data from list to map with out using a loop?
("15"); how to get this data into map with out using a loop. i want this data like this--map.put(name,id); Is it possible to do without using loop...how to get data from list to map with out using a loop?  List list
loop gymnastics,new for in loop gymnastics,result set Iterable,java newsletter,tutorial
New for/in loop gymnastics 2005-02-07 The Java Specialists' Newsletter [Issue 103] - New for/in loop gymnastics Author: Dr. Heinz M. KabutzJDK version.... New for/in loop gymnastics The new for/in loop gives us
Loops - Introduction
iteration. The for loop groups these three common parts together into one... of loop statements is to repeat Java statements many times. There are several kinds of loop statements in Java. while statement - Test
For..in loop
For..in loop         In this tutorial we will study for..in loop which is similar to for each loop of C#, Java and other popular languages, in this example
Java find prime numbers without using break statement
Java find prime numbers without using break statement In this tutorial, you will learn how to find the prime numbers without using break statement. You all.... In many of the programs, break statement is used to quit the loop. Actually
Java for loop
Java for loop  Can a for statement loop indefinitely
without scanner
without scanner  a company need a system to store the data about the employees , the number of employees is dynamic , you need to store the following attributes : name , age , salary and note that we need to solve it using array
For Loop - Struts
For Loop  Hi, How to use for loop in Struts2. I don't want use.... How to use the For loop in JSP. Thanks, Rajesh.  Hi Rajesh, i am sending simple use of for loop. In this example, you will see the use
for( ) loop in php
for( ) loop in php  Generally, when we use for loop in PHP or any other programming language why we use i++ and not ++i. What is the reason behind
for( ) loop in php
for( ) loop in php  Generally, when we use for loop in PHP or any other programming language why we use i++ and not ++i. What is the reason behind
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.