0% found this document useful (0 votes)
2 views1 page

Java Exercise and Answers With Name-1

The document contains a Java programming exercise by Sakarie Mohomed Omer, which includes a countdown, a quote, personal information, and examples of variable declaration and usage. It also discusses the difference between character strings and string literals, as well as creating objects and reading user input using the Scanner class. The exercise demonstrates basic Java syntax and concepts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Java Exercise and Answers With Name-1

The document contains a Java programming exercise by Sakarie Mohomed Omer, which includes a countdown, a quote, personal information, and examples of variable declaration and usage. It also discusses the difference between character strings and string literals, as well as creating objects and reading user input using the Scanner class. The exercise demonstrates basic Java syntax and concepts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

You might also like