Java Loops Exercises
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
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
What is the output of this code? import java.util.ArrayList; class Main { public static void main(String[] args) { ArrayList userPermissions = new ArrayList(); userPermissions.add(“Read”); userPermissions.add(“Write”); userPermissions.add(“Delete”); userPermissions.add(“Publish”); int index = 3; System.out.println(userPermissions.get(index)); } } Publish Delete Submit Display the first permission of the ArrayList. import java.util.ArrayList; class Main { public static void main(String[] args) { […]
Call the custom function. class Main { public static void main(String[] args) { “” } public static void printHelloJava(){ System.out.println(“Hello Java!”); } } Submit What is the output of this code? class Main { public static void main(String[] args) { printHelloJava(); printHelloJava(); } public static void printHelloJava(){ System.out.println(“Hello Java!”); } } Hello Java! Hello Java! […]
Write a condition that checks if the item is affordable. class Main { public static void main(String[] args) { double itemPrice = 1900.25; double wallet = 2100.50; if “”{ System.out.println(“The item is affordable!”); } } } fileSizeLimitation){ System.out.println(“File size exceeds the maximum allowable limit.”); System.out.println(“Please choose a smaller file.”); } } } Submit Check if […]
Add 10 to the numberOfItems variable. class Main { public static void main(String[] args) { int numberOfItems = 30; numberOfItems = “” } } ; numberOfItems 10 + += Submit Subtract 5 from the speed variable. class Main { public static void main(String[] args) { int speed = 120; speed = speed “” 10; } […]
What is the output of this code? class Main { public static void main(String[] args) { int numberOfAttendance = 10; int seats = 18; boolean areSeatsEnough = seats >= numberOfAttendance; System.out.println(“Are seats enough? ” + areSeatsEnough); } } Are seats enough? true Are seats enough? false Submit This code checks if a product is in […]
What is type casting in Java? Declaring a variable with a specific data type Converting a value from one data type to another Submit What will be the value of the roundedPi ? class Main { public static void main(String[] args) { double pi = 3.14159; int roundedPi = (int) pi; System.out.println(“Rounded Pi: ” + […]
Choose the proper data type. class Main { public static void main(String[] args) { “” result = Math.max(30, 33); System.out.println(result); } } int String boolean Submit Choose the proper data type. class Main { public static void main(String[] args) { “” result = Math.max(30.2, 33.1); System.out.println(result); } } double long int Submit Choose the proper […]
Choose the proper data type. class Main { public static void main(String[] args) { “” department = “Marketing”; } } int String short Submit Choose the proper data type. class Main { public static void main(String[] args) { “” birthYear = 2007; } } float short Submit Choose the proper data type. class Main { […]
Use camel case convention to name this variable. class Main { public static void main(String[] args) { String “” = “Yesterday”; } } lastseen lastSeen last_seen Submit Use numbers to define related variables. class Main { public static void main(String[] args) { String securityQuestion1 = “What was the name of your first pet?”; String securityQuestion2 […]