1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
/* Simple For loop Example This Java Example shows how to use for loop to iterate in Java program. */ public class SimpleForLoopExample { public static void main(String[] args) { /* Syntax of for loop is * * for(<initialization> ; <condition> ; <expression> ) * <loop body> * * where initialization usually declares a loop variable, condition is a * boolean expression such that if the condition is true, loop body will be * executed and after each iteration of loop body, expression is executed which * usually increase or decrease loop variable. * * Initialization is executed only once. */ for(int index = 0; index < 5 ; index++) System.out.println("Index is : " + index); /* * Loop body may contains more than one statement. In that case they should * be in the block. */ for(int index=0; index < 5 ; index++) { System.out.println("Index is : " + index); index++; } /* * Please note that in above loop, index is a local variable whose scope * is limited to the loop. It can not be referenced from outside the loop. */ } } /* Output would be Index is : 0 Index is : 1 Index is : 2 Index is : 3 Index is : 4 Index is : 0 Index is : 2 Index is : 4 */ |
How can I assign the value of an int variable to the initiialization of a “for” loop
plz insert much more example for looping, array,string,methods,inhertitance,etc in java
for (int i=10;i>=1;i–){
for (int j=1;j<=i;j++){
System.out.print(” “);
}for (int j=10;j>=i;j–){
System.out.print(“*”);
}for (int l=9;l>=i;l–){
System.out.print(“*”);
}System.out.println();
}
for (int i=8;i>=0;i–){
for (int j=9;j>=i;j–){
System.out.print(” “);
}for (int k=0;k<=i;k++){
System.out.print(“*”);
}for (int j=1;j<=i;j++){
System.out.print(“*”);
}System.out.println();
}
}
}
plz help me make this program that the output wil b this way..
* * * *
* *
* *
* * * *
can you help me ? a looping program that wil have a ouput of
* *
* *
* * * * * *
* *
* *
* *
how to get output like this using for loop
1
2 3
4 5 6
7 8 9 10
Did i will insert import java.util.*;
in using for loop in java?
no. i think you can use loop directly.But if you use scanner you need to call it
help me make this program that the output will be this way!
*
* *
* * *
* * * *
* * * *
* * *
* *
*
for(int i=0;i<=8;i++)
{
for(int j=0;j<=i;j++)
{
System.out.print(“*”);
}
System.out.println();
}
for(int i=8;i>=0;i–)
{
for(int j=0;j<=i;j++)
{
System.out.print(“*”);
}
System.out.println();
}
While applying a for loop i am getting the output elements one below the other . What should I do to get the out put in a single row?