Name: Sakarie Mohomed Omer
Java Programming Exercise – Answers
Part A: Java Program
public class Exercise { public static void main(String[] args) { // Countdown
[Link]("5"); [Link]("4"); [Link]("3");
[Link]("2"); [Link]("1"); // Quote on multiple lines
[Link]("Education is the most powerful weapon");
[Link]("which you can use"); [Link]("to change the world.");
// Keyboard numbers [Link]("1 2 3"); [Link]("4 5 6");
[Link]("7 8 9"); [Link]("0"); // Tuna statement
[Link]("I want to have 24.5 tuna"); // Personal information
[Link]("Hometown: Hargeisa"); [Link]("Area Code: 252");
[Link]("Address: Main Street"); [Link]("Height: 170 cm");
[Link]("Weight: 65 kg"); } }
Part B: Theory Questions
1. Character String vs String Literal: A character string is stored in a variable, while a string literal
is written directly inside double quotes.
2. Declaring a Variable: Example: int age = 20;
3. Using Variables: Variables store values that can change during program execution.
4. Creating an Object using new: Example: Scanner sc = new Scanner([Link]);
5. Program asking Name, Age, Hometown: Uses Scanner to read user input.
6. Printing a String from User: Reads a string using Scanner and prints it.