Simple for loop example in Java
class ForLoop {
public static void main(String[] args) {
int c;
for (c = 1; c <= 10; c++) {
System.out.println(c);
}
}
}
Java for loop example to print stars in console
class Stars {
public static void main(String[] args) {
int row, numberOfStars;
for (row = 1; row <= 10; row++) {
for(numberOfStars = 1; numberOfStars <= row; numberOfStars++) {
System.out.print("*");
}
System.out.println(); // Go to next line
}
}
}
class ForLoop {
public static void main(String[] args) {
int c;
for (c = 1; c <= 10; c++) {
System.out.println(c);
}
}
}
Java for loop example to print stars in console
class Stars {
public static void main(String[] args) {
int row, numberOfStars;
for (row = 1; row <= 10; row++) {
for(numberOfStars = 1; numberOfStars <= row; numberOfStars++) {
System.out.print("*");
}
System.out.println(); // Go to next line
}
}
}
No comments:
Post a Comment