0% found this document useful (0 votes)
3 views5 pages

Java Programs: Basics and Outputs

The document presents five Java programs with specific aims: printing 'Hello World', adding two numbers, checking if a number is odd or even, finding the largest among three numbers, and printing a multiplication table. Each program includes its code, output, and a result statement confirming successful execution. The examples illustrate basic programming concepts and operations in Java.

Uploaded by

monicabungla
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)
3 views5 pages

Java Programs: Basics and Outputs

The document presents five Java programs with specific aims: printing 'Hello World', adding two numbers, checking if a number is odd or even, finding the largest among three numbers, and printing a multiplication table. Each program includes its code, output, and a result statement confirming successful execution. The examples illustrate basic programming concepts and operations in Java.

Uploaded by

monicabungla
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

PROGRAM 1 – Print Hello World

AIM: To print Hello World on the screen.


CODE:
public class Hello {
public static void main(String[] args) {
[Link]("Hello World");
}
}

OUTPUT:
Hello World
RESULT: The program successfully prints Hello World.
PROGRAM 2 – Add Two Numbers
AIM: To add two integers and display the result.
CODE:
public class AddNumbers {
public static void main(String[] args) {
int a = 10, b = 20;
int sum = a + b;
[Link]("Sum = " + sum);
}
}

OUTPUT:
Sum = 30
RESULT: The program successfully adds two numbers.
PROGRAM 3 – Check Odd or Even
AIM: To check whether a number is odd or even.
CODE:
public class OddEven {
public static void main(String[] args) {
int num = 7;
if(num % 2 == 0)
[Link]("Even Number");
else
[Link]("Odd Number");
}
}

OUTPUT:
Odd Number
RESULT: The program successfully checks odd/even.
PROGRAM 4 – Find Largest of Three
Numbers
AIM: To find the largest among three numbers.
CODE:
public class Largest {
public static void main(String[] args) {
int a = 15, b = 22, c = 9;
if(a > b && a > c)
[Link]("A is Largest");
else if(b > c)
[Link]("B is Largest");
else
[Link]("C is Largest");
}
}

OUTPUT:
B is Largest
RESULT: The program successfully finds the largest number.
PROGRAM 5 – Print Multiplication Table
AIM: To print the multiplication table of a number.
CODE:
public class Table {
public static void main(String[] args) {
int num = 5;
for(int i = 1; i <= 10; i++) {
[Link](num + " x " + i + " = " + (num * i));
}
}
}

OUTPUT:
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
RESULT: The program successfully prints the multiplication table.

You might also like