Its simple:
String a="Suraj Acharya"//consider this to be your string
for(int i=0;i<a.length();i++)
System.out.println("Its Simple");
You may exit a nested loop in Java using a break with a label for the outer loop.
Java has three kinds of loops 1. For Loop 2. While Loop 3. Do - While Loop Both For loop and While loop would iterate through a certain lines of code within the loop's limit as long as the loop condition is satisfied. A do while loop would execute the loop once even before checking the condition. So in a do while loop, even if the loop condition is not satisfied the loop would execute once. Example Declarations: for(int i = 0; i < n; i++) { ..... } while (i < n) { ... i++; } do { ... i++; } while (i < n) ;
It's best to use a for loop.For example, if you want 10 iterations:for (int i = 1; i
Use loops. int i; // for loop for(i = 0; i < 10; ++i) { System.out.println(i); } // do loop i = 0; do { System.out.println(i++); } while(i < 10); // while loop i = 0; while(i < 10) { System.out.println(i++); } Each of the above blocks of code will print the values 0-9. Replace the body of the loops to make the code it executes useful. Replace the conditions to change when the loops exit.
If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).
You may exit a nested loop in Java using a break with a label for the outer loop.
Java has three kinds of loops 1. For Loop 2. While Loop 3. Do - While Loop Both For loop and While loop would iterate through a certain lines of code within the loop's limit as long as the loop condition is satisfied. A do while loop would execute the loop once even before checking the condition. So in a do while loop, even if the loop condition is not satisfied the loop would execute once. Example Declarations: for(int i = 0; i < n; i++) { ..... } while (i < n) { ... i++; } do { ... i++; } while (i < n) ;
It's best to use a for loop.For example, if you want 10 iterations:for (int i = 1; i
for loop function
in a loop
Use loops. int i; // for loop for(i = 0; i < 10; ++i) { System.out.println(i); } // do loop i = 0; do { System.out.println(i++); } while(i < 10); // while loop i = 0; while(i < 10) { System.out.println(i++); } Each of the above blocks of code will print the values 0-9. Replace the body of the loops to make the code it executes useful. Replace the conditions to change when the loops exit.
If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).
12345 1234 123 12 1
Loop through some numbers - for example, 2 through 100 - and check each one whether it is a prime number (write a second loop to test whether it is divisible by any number between 2 and the number minus 1). If, in this second loop, you find a factor that is greater than 1 and less than the number, it is not a prime, and you can print it out.
the multiplication of the number of iterations with the number of statements in that loop is equal to loop length.
1) use for loop 2) do while loop
Use the System.out.println() to do the actual printing. In Java, you can directly concatenate (combine) a number with a text. For example, if your number is in the variable called "x": System.out.println(x + "#####"); If you want to combine different print commands, for example to print several hash characters in a loop, note that println() will add a new line, while print() will not.