[Go to site: main page, start]

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

Java 5 Programs With Output

The document contains several Java programs demonstrating basic programming concepts. It includes examples such as printing 'Hello, World!', adding two numbers, determining if a number is even or odd, printing numbers from 1 to 5, and finding the largest of two numbers. Each program is followed by its expected output.

Uploaded by

dakshtomar191
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)
4 views1 page

Java 5 Programs With Output

The document contains several Java programs demonstrating basic programming concepts. It includes examples such as printing 'Hello, World!', adding two numbers, determining if a number is even or odd, printing numbers from 1 to 5, and finding the largest of two numbers. Each program is followed by its expected output.

Uploaded by

dakshtomar191
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

1.

Hello World Program


class HelloWorld {
public static void main(String[] args) {
[Link]("Hello, World!");
}
}
Output: Hello, World!

2. Add Two Numbers


class AddNumbers {
public static void main(String[] args) {
int a = 10;
int b = 20;
int sum = a + b;
[Link]("Sum = " + sum);
}
}
Output: Sum = 30

3. Even or Odd
class EvenOdd {
public static void main(String[] args) {
int num = 7;
if (num % 2 == 0)
[Link]("Even number");
else
[Link]("Odd number");
}
}
Output: Odd number

4. Print Numbers 1 to 5
class PrintNumbers {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
[Link](i);
}
}
}
Output: 1 2 3 4 5

5. Largest of Two Numbers


class LargestNumber {
public static void main(String[] args) {
int a = 15;
int b = 25;
if (a > b)
[Link]("A is larger");
else
[Link]("B is larger");
}
}
Output: B is larger

You might also like