100% found this document useful (1 vote)
1K views

Java Basic Worksheet

The document provides solutions to 4 Java exercises: 1) Print "Hello" and a name, 2) Print the sum of two numbers, 3) Print the division of two numbers, and 4) Print the result of multiple operations involving addition, subtraction, multiplication, division, and modulo. Each exercise includes the code to write and sample solution code.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views

Java Basic Worksheet

The document provides solutions to 4 Java exercises: 1) Print "Hello" and a name, 2) Print the sum of two numbers, 3) Print the division of two numbers, and 4) Print the result of multiple operations involving addition, subtraction, multiplication, division, and modulo. Each exercise includes the code to write and sample solution code.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Basic: Exercise-1 with Solution

Write a Java program to print 'Hello' on screen and then print your name on a
separate line.

Sample Solution:

Java Code:
public class Main {

public static void main(String[] args) {


System.out.println("Hello\nCoco Martin!");
}

Java Basic: Exercise-2 with Solution


Write a Java program to print the sum of two numbers.

Sample Solution:

Java Code:
public class Main {

public static void main(String[] args) {


System.out.println(24+26);
}

}
Java Basic: Exercise-3 with Solution
Write a Java program to divide two numbers and print on the screen.

Sample Solution:

Java Code:
public class Main {

public static void main(String[] args) {

System.out.println(50/3);

Java Basic: Exercise-4 with Solution


Write a Java program to print the result of the following operations.

Sample Solution:

Java Code:
public class Main {

public static void main(String[] args) {

System.out.println(-5 + 8 * 6);

System.out.println((55+9) % 9);

System.out.println(20 + -3*5 / 8);

System.out.println(5 + 15 / 3 * 2 - 8 % 3);

You might also like