-
Write a Java program that prints numbers from 0 to 10 including 10.
class Main { public static void main(String[] args) { for(int i = 0; i <= 10; i++){ System.out.println(""); } } }
-
Write a Java program that prints numbers from 1 to 10 including 10.
class Main { public static void main(String[] args) { for(int i = ""; i <= 10; i++){ System.out.println(i); } } }
-
Write a Java program that prints 1 to 10 and not including 10.
class Main { public static void main(String[] args) { for(int i = 1; i "" 10; i++){ System.out.println(i); } } }
-
Write a Java program that prints even numbers from 0 to 10 including 10.
class Main { public static void main(String[] args) { for(int i = 0; i <= 10; i += 2){ System.out.println(i); } } }
-
Print odd numbers between 0 to 10 including 10.
class Main { public static void main(String[] args) { for(int i = ""; i <= 10; i += 2){ System.out.println(i); } } }
-
what is the output of this program?
class Main { public static void main(String[] args) { for(int i = 10; i >= 0; i--){ System.out.println(i); } } }
-
What is the output of this Java program?
import java.util.ArrayList; class Main { public static void main(String[] args) { ArrayList
inventory = new ArrayList<>(); inventory.add("Product A"); inventory.add("Product B"); inventory.add("Product C"); inventory.add("Product D"); for (int i = 0; i <= 3; i++){ System.out.println(inventory.get(i)); } } } -
What is the output of this program?
import java.util.ArrayList; class Main { public static void main(String[] args) { ArrayList
inventory = new ArrayList<>(); inventory.add("Product A"); inventory.add("Product B"); inventory.add("Product C"); inventory.add("Product D"); for (int i = 0; i < 3; i++){ System.out.println(inventory.get(i)); } } } -
What is the output of this code?
import java.util.ArrayList; class Main { public static void main(String[] args) { ArrayList
inventory = new ArrayList<>(); inventory.add("Product A"); inventory.add("Product B"); inventory.add("Product C"); inventory.add("Product D"); for (int i = 0; i <= inventory.size() - 1; i++){ System.out.println(inventory.get(i)); } } } Java Exercises for Loops
If you've faced difficulties with these exercises, take a look at Loops Module on my Java course.
You can also share 'Java Loops' Exercises on your:
X (Twitter) - Telegram - Linkedin - Facebook - or on your favorite platform...