Level 1: Basic Syntax & Setup
Code Exp:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Java Adventurer!");
Output: Hello, Java Adventurer!
To Do:
Focus: Printing, Comments, Java Structure
1. Print your full name and favorite quote.
2. Write a program that displays:
Name: [Your Name]
Age: [Your Age]
Hobby: [Your Hobby]
[Note: Add both single-line and multi-line comments to describe what your code
is doing.]
3. Write a Java program that prints the following pattern
• *
• **
• ***
• ****
H.W: 1. Write a Java program that declares two variables, name (a String) and age (an
integer), and prints them in the following format:
My name is [name] and I am [age] years old.
2. Write a Java program to print the numbers 1 to 5, each on a new line, using a for loop.
Add:
• A single-line comment above the loop explaining what it does.
• A multi-line comment at the start of the program describing its purpose.
Level 2: Variables, Data Types, and Input:
Code exp:
import java.util.Scanner;
public class UserInfo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
System.out.println("Hello, " + name + "!");
}
}
Output: Hello, Swapnoneel!
public class VariableTypes {
public static void main(String[] args) {
int age = 15;
double height = 5.6;
char grade = 'O';
String name = "Swap";
System.out.println("Age: " + age);
System.out.println("Height: " + height + " feet");
System.out.println("Grade: " + grade);
System.out.println("Name: " + name);
}
}
Output: Age: 15 Height: 5.6 feet Grade: O Name: Swap
To Do:
1. Ask the user for two numbers and print their sum, difference, product, and divide.
2. Create a program that takes a user's name and age, then prints:
Hello [name], you are [age] years old.
3. Write a Java program that takes a user’s name (as a String) and age (as an int) as input
using the Scanner class, then prints a message in the format:
Hello, [name]! You are [age] years old.
H.W:
1. Write a Java program that declares an int variable with the value 10 and a double
variable with the value 5.5. Perform the following: Add the two variables and store the
result in a double variable (requires type casting)
2. Code has errors related to variables, data types, and input. Fix the code so it takes a
user’s favorite number (as an int) and prints:
Your favorite number is: [number]
Code:
import java.util.scanner;
class FavoriteNumber
scanner input = new scanner(System.in);
System.out.println("Enter your favorite number: ");
int number = input.nextint;
System.out.println("Your favorite number is: " + number)