0% found this document useful (0 votes)
3 views

Write Java Programs 2024

The document contains Java programs for various tasks, including printing names, country names, school details, and performing arithmetic operations. It also includes programs for checking even/odd numbers, voting eligibility, admission eligibility, and calculating simple interest. Each program is structured with a class and a main method, demonstrating basic Java syntax and functionality.

Uploaded by

ruqayyariyaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Write Java Programs 2024

The document contains Java programs for various tasks, including printing names, country names, school details, and performing arithmetic operations. It also includes programs for checking even/odd numbers, voting eligibility, admission eligibility, and calculating simple interest. Each program is structured with a class and a main method, demonstrating basic Java syntax and functionality.

Uploaded by

ruqayyariyaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Write Java programs for the following:-

1. To Print your name:

public class name


{
public static void main(String args[])
{
System.out.println("My name is Maria");
}
}
_________________________________________________________________________
2. To Print 5 country names :

public class countries


{
public static void main(String args[])
{
System.out.println("Five country names are");
System.out.println("1. India");
System.out.println("2. Srilanka");
System.out.println("3. Pakistan");
System.out.println("4. China");
System.out.println("5. America");
}
}
___________________________________________________________________________
____
3. To Print 5 lines about your school:

public class school


{
public static void main(String args[])
{
System.out.println(‘’’My School is the best school of the city. It is in Fraser Town, Bangalore.
My school name is St. Francis Xavier Girls' High School. I love to go to my school very much.
It has a big playground. It also has a big computer lab. My school has been ranked 1st due
to its greenery. My school focuses on the knowledge of students. ‘’’);
}
}
___________________________________________________________________________
4. To declare a variable and initialize it with the value of 10 :

public class declare


{
public static void main(String args[])
{
int i=10;
System.out.println("The value of i is"+i);
}
}
___________________________________________________________________________
__
5. To Print “Welcome to the world of Artificial Intelligence”:

public class AI
{
public static void main(String args[])
{
System.out.println("Welcome to the world of Artifical Intelligence");
}
}
__________________________________________________________________________
6. To Print general details about yourself:

public class myself


{
public static void main(String args[])
{
System.out.println("My family is a group of 4 family members.");
System.out.println(“My family includes-My Mother, Father, elder sister and myself”);
System.out.println("We went to a hill station for the summer vacation");
System.out.println("I love my family very much.");

}}
________________________________________________________________________

7. To calculate the sum of two given numbers 2060 and 5999:

public class sum


{
public static void main(String args[])
{
int x,y,sum;
x=2060; y=5999;
sum=x+y;
System.out.println("The sum of 2060 and 5999 is "+sum);
}
}
___________________________________________________________________________
8. To find the average of 20, 40 and 99:

public class avg


{
public static void main(String args[])
{
int p,q,r,average;
p=20;q=40;r=99;
average=(p+q+r)/3;
System.out.println("The average of the three numbers is "+average);
}
}
___________________________________________________________________________

9. To interchange the value of two numbers without using third variable.

public class swap


{
public static void main(String args[])
{
int x,y;
x=10;y=15;
System.out.println("Before swap");
System.out.println("x="+x);
System.out.println("y="+y);
x = x + y;
y = x - y;
x = x -y;
System.out.println("After swap");
System.out.println("x="+x);
System.out.println("y="+y);
}
}
________________________________________________________________________
10. To find the product of two numbers x and y, where x=250 and y=400.

public class product


{
public static void main(String args[])
{
int x,y,Product;
x=250; y=400;
Product=x*y;
System.out.println("The Product of 250 and 400 is "+Product);
}
}
_________________________________________________________________________
11. A car takes 3 hours to drive a distance of 192km. Create a program to calculate the
average speed in Km/h.

public class speed


{
public static void main(String args[])
{
int d,t,s;
d=192; t=3;
s=d/t;
System.out.println("The average speed of the vehicle is "+s);
}
}
__________________________________________________________________________

12. To calculate and print the circumference and area of a circle.

public class circle


{
public static void main(double radius)
{
double area, circumference,pi;
pi=3.14;
area=pi*radius*radius;
System.out.println("Area of a circle :"+area);
circumference=2*pi*radius;
System.out.println("Circumference of a circle :"+circumference);
}
}
_________________________________________________________________________
13. To print * symbol in a pyramid form:

public class star_symbol


{
public static void main(String args[])
{
System.out.println(" * ");
System.out.println(" * * * ");
System.out.println(" * * * * ");
System.out.println("* * * * * ");
}
}
14. To print @ symbol in a pyramid form:

public class At_symbol


{
public static void main(String args[])
{
System.out.println(" @ ");
System.out.println(" @@@ ");
System.out.println(" @@@@@ ");
System.out.println(" @@@@@@@ ");
System.out.println(" @@@@@@@@@ ");
System.out.println("@@@@@@@@@@@ ");
}
}
___________________________________________________________________________
15. To print $ symbol in a pyramid form:

public class dollar_symbol


{
public static void main(String args[])
{
System.out.println(" $ ");
System.out.println(" $$$ ");
System.out.println(" $$$$ ");
System.out.println(" $$$$$ ");
System.out.println(" $$$$$$$ ");
System.out.println(" $$$$$$$$ ");
}
}

16. To find whether the given number is Even or odd :

public class Even_Odd


{
public static void main(int num)
{
System.out.println(“Entered number is “+num);
if(num%2==0)
System.out.println(“Number is even”);
else
System.out.println(“Number is odd”);
}
}
___________________________________________________________________________
___
17. To check whether the person is Eligible to vote or not:

public class vote


{
public static void main(int age)
{
System.out.println(“Enter your age “+age);
if(age>=18)
System.out.println(“You are eligible to vote”);
else
System.out.println(“You are not eligible to vote”);
}
}
___________________________________________________________________________
18. To check whether the child is eligible for Prep1 or Prep2 admission:

public class LKG


{
public static void main(double age)
{
System.out.println("Entered age is "+age);
if(age<4)
{
System.out.println("Not eligible");
}
else if(age>4 && age<5)
{
System.out.println("Eligible for Prep1 admission");
}
else if(age>5)
{
System.out.println("Eligible for Prep2 admission");
}}}
___________________________________________________________________________

19. To check whether the given number is equal to Zero or not:


public class zero
{
public static void main(int num)
{
if(num<0)
{
System.out.println(“The given number is negative:“);
else if(num>0)
{
System.out.println(“The given number is positive:“);
}
else
{
System.out.println(“The given number is equal to Zero”);
}
}
}
}
___________________________________________________________________________
20. Calculate Simple Interest where p=6000, n=2 and r-10. Hint: Formula to finr Simple
Interest is SI = (p*n*r)/100:

public class Simple_Interest


{
public static void main(String args[])
{
int p=6000, n=2, r=10;
float SI;
SI = (p*n*r)/100;
System.out.println(“The Simple Interest is Rs “+SI);
}
}

You might also like