Can anyone please give me an example of input inside the loop in java program?
Answers
Answered by
1
import java.io.*;
class Loop
{
public static void main( )throws IOException
{
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
System.out.println("enter value");
for(int I=0;I<5;I++)
{
int n=Integer.parseInt(br.readLine( ));
}
}
}
class Loop
{
public static void main( )throws IOException
{
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
System.out.println("enter value");
for(int I=0;I<5;I++)
{
int n=Integer.parseInt(br.readLine( ));
}
}
}
Ritammukherjee:
Ok sir no problem
Answered by
19
Loop used in JAVA
A loop is a repetition of a function .
For example :
class random
{
void main()
{
for ( int i = 0 ; i <=5 ; i++ )
{
System.out.println ( "Help ") ;
}
}
}
OUTPUT :
Help
Help
Help
Help
Help
You can clearly understand that loop is used to repeat a task several times .
Here I have printed "Help" several times thats it !
Now I will give an example of while-loop :
class jishnu
{
void main()
{
int n=2;
while(n!=0)
{
System.out.println(n);
n--;
}
}
}
OUTPUT :
2
1
The basic thing in a while loop is that it checks the condition and if the condition is satisfied then only the loop will be continued .
Similar questions