[Go to site: main page, start]

0% found this document useful (0 votes)
14 views2 pages

Java Programs for Beginners

The document contains Java programs for basic tasks: printing 'HELLO WORLD', adding two numbers, multiplying two numbers, and checking if a number is odd or even. Each program includes a class definition and a main method that executes the respective functionality. The code snippets demonstrate fundamental programming concepts in Java.

Uploaded by

arorafamily2005
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)
14 views2 pages

Java Programs for Beginners

The document contains Java programs for basic tasks: printing 'HELLO WORLD', adding two numbers, multiplying two numbers, and checking if a number is odd or even. Each program includes a class definition and a main method that executes the respective functionality. The code snippets demonstrate fundamental programming concepts in Java.

Uploaded by

arorafamily2005
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

JAVA PROGRAMS

Q1. WRITE A PROGRAM TO PRINT A MESSAGE “HELLO WORLD”.

public class HELLO {

public sta c void main(String[] args) {

[Link]("HELLO WORLD!!");

Q2. WRITE A PROGRAM TO ADD TWO NUMBERS.

public class ADDNUMBERS{

public sta c void main(String[] args) {

int num1 = 5, num2 =10, sum;

sum = num1 + num2;

[Link]("Sum of "+ num1 + "and" + num2 + "is" + sum);

Q3. WRITE A PROGRAM TO MULTIPLY TWO NUMBERS.

public class mul ply {

public sta c void main(String[] args) {

double first = 2.5, second = 4.5, product;

product = first * second;

[Link]("The product is " + product);

}
Q4. WRITE A PROGRAM TO CHECK WHETHER GIVEN NUMBER IS ODD OR EVEN

public class Even {

public sta c void main(String[] args) {

int num = 5;

if (num%2 == 0)

[Link]( num + "is even");

else

[Link]( num + "is odd");

You might also like