#5 Looping : For loop
import java.io.*;
public class For_Loop
{
public static void main(String args[])
{
for(int start=0; start<=10; start++)
{
System.out.println(start);
}
}
}
Output:
0
1
2
3
4
5
6
7
8
9
10
_________________________________________________________________________________
import java.io.*;
public class For_Loop
{
public static void main(String args[])
{
for(int start=0; start<=10; start++)
{
System.out.println(start);
}
}
}
Output:
0
1
2
3
4
5
6
7
8
9
10
_________________________________________________________________________________
Tip 5: Default access modifier is "public".
#6 While Loop:
import java.io.*;
public class While_Loop
{
public static void main(String args[])
{
int i=0;
while(i<5)
{
System.out.println(i);
i++;
}
}
}
Output:
0
1
2
3
4
_________________________________________________________________________________
Tip 6: Main Program will execute first.
# 7 Do - While Loop :
import java.io.*;
public class Do_While
{
public static void main(String args[])
{
int i=1;
do
{
System.out.println(i);
i++;
}while(i<5);
}
}
Output:
1
2
3
4
__________________________________________________________________________________
#Tip 7: Do-while loop is guarantees to print at least once.
No comments:
Post a Comment