0% found this document useful (0 votes)
35 views4 pages

Class8 Ch5 Java Programs

Uploaded by

Sonal Gupta
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)
35 views4 pages

Class8 Ch5 Java Programs

Uploaded by

Sonal Gupta
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

Program1. Write a program to print, "Welcome to the World of Artificial Intelligence".


class display
{
public static void main( )
{
[Link](“Welcome to the World of Artificial Intelligence");
}
}
Output-
Welcome to the World of artificial Intelligence

Program2. Write a program to print the general details about your school in five lines.
class School_detail
{
public static void main()
{
[Link] (“Name: The Indian Heritage School");
[Link] ("Board: ICSE");
[Link] ("Classes: Nursery to XII” );
[Link] ("Shamshabad Road ");
[Link]. println ("Agra, UP");
}
}
Output-
Name: The Indian Heritage School
Board: ICSE
Classes: Nursery to XII
Shamshabad Road
Agra, UP

Program3. Write a program to calculate the sum of two given numbers 2060 and 5999.
class Sum
{
public static void main( )
{
int a=2060, b=5999, S;
S= a+b;
[Link] ("Sum= "+S);
}
}

Program 4. Write a program to find the average of the three numbers 40, 85 and 115.
class Average
{
public static void main( )
{
int a=40,b=85, c=115;
double Avg;
Avg = (a+b+c)/3.0;
[Link] (“Average" + Avg);
}
}

Program5. Write a program to interchange the value of two numbers without using the third variable.
class Swap
{
public static void main(int a, int b)
{
[Link]("First no =”+ a );
[Link]("Second no = "+b);
a = a + b;
b = a – b;
a = a – b;
[Link] ("After swapping first no=”+ a);
[Link] ("After swapping second no =”+ b);
}

Program6. Write a program to find the product of two numbers x and y, where x = 150 and y = 200.

class Product

public static void main( )

int x = 150 ,y = 200, Prod;

Prod = x * y;

[Link]("Product =”Prod);

Program7. It takes 3 hours to drive a distance of 192 km. Create a progam to calculate the average speed in
km/h.

class Speed

public static void main( )


{

double t = 3 ,d = 192, S;

S = d / t;

[Link]("Speed =”+S +”km/h”);

Program8. Create a program to calculate and print the circumference and area of a circle.

class Circle

public static void main(double r)

double Pi= 3.14, Area, Peri;

Peri = 2 * Pi * r;

Area = Pi * r *r;

[Link]("Perimeter=” + Peri);

[Link], println ("Area= “+ Area);

Program9. Create a program to calculate area of a rectangle.

class Rectangle

public static void main (int l, int b)

int Area;

Area = l*b;

[Link] ("Area= “+ Area);

Program10. Enter 2 numbers and Find their quotient and remainder by dividing the 1st no. by the 2nd no.
class divide

public static void main(int a, int b)

int Q, R;

Q= a / b;

R=a% b;

[Link]("Quotient =”+ Q);

[Link] (“Remainder=” + R);

GIVE OUTPUT

[Link]("Welcome ");

[Link]("to Java ");

[Link]("World ");

[Link] ("This is ");

[Link] ("my first ");

[Link] ("Java ”);

[Link] ("Program");

Output-

Welcome to Java
World
This is my first
Java Program

You might also like