Computer Project Class 9
Computer Project Class 9
STUDIES
NAME – KUSHAGRA SINGH
CLASS- 9-B
PERSONAL NO. – 18732
TOPIC- JAVA PROGRAMS
ACKNOWLEDGEMENT
I would like to thank Ms/Mr. for her/his valuable guidance
and help. She/he clarified all my
queries about the project without which I would have not
been able to complete the project. I
would also like to thank my family for providing all
necessary materials and my friends forhelping me with this
project.
THANK YOU
PROGRAM 1 –
Write a program using Java language to generate the sum of
three different numbers.
public class SumCalculator {
public static void main(String[] args) {
int number1 = 5;
int number2 = 10;
int number3 = 15;
System.out.println("The sum of " + number1 + ", " + number2 + ", and " +
number3 + " is: " + sum);
}
}
Variable name Data Type of the Variable Purpose of the Variable
number 1 int To Store Number
number 2 int To Store Number
number 3 int To Store Number
sum int To add the stored
numbers
PROGRAM 2-
Write a program using Java language to generate the cube
of first ten even numbers using while loop.
public class CubeCalculator
{
public static void main(String[] args)
{
int number = 2;
int count = 1;
while (count <= 10)
{
int cube = number * number * number;
System.out.println("Cube of " + number + " is: " + cube);
number += 2;
count++;
}
}
}
Variable name Data Type of the Variable Purpose of the Variable
number int To keep track of numbers
count int To keep track of the
count
cube int To find the cube of
number
PROGRAM 3-
Write a program using Java language to find the square of a
given number.
PROGRAM 4-
Write a program using Java language to generate the cube
of a given number.
PROGRAM 5-
Write a program using Java language to check whether a
given number is an even number or an odd number.
public class EvenOddChecker
{
public static void main(String[] args)
{
int number = 7;
if (number % 2 == 0)
System.out.println(number + " is an even number.");
else
System.out.println(number + " is an odd number.");
}
}
}
Variable name Data Type of the Variable Purpose of the Variable
number int To store numbers
PROGRAM 6-
Write a program using Java language to check whether a
given number is positive, negative or zero and display the
appropriate message accordingly
PROGRAM 7-
Write a program using Java language to generate the table
of any given number up to ten counts.
PROGRAM 8-
Write a program using Java language to generate first ten
even numbers using do-while( ) loop.
PROGRAM 10-
Write a program using Java language to generate the square
of first ten natural numbers.
PROGRAM 11-
Write a program using Java language to print the days of
the week using a switch-case statement.
PROGRAM 12 –
Write a program using Java language to input ten numbers
and display only those numbers which are divisible by 7.
import java.util.Scanner;
public class DivisibleBySevenChecker
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
scanner.close();
}
}
Variable name Data Type of the Variable Purpose of the Variable
i int To use in for loop
PROGRAM 13-
Write a program using Java language to input a year( in
four digits) and then check whether it is a leap year or not.
import java.util.Scanner;
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
System.out.println(year + " is a leap year.");
} else {
System.out.println(year + " is not a leap year.");
}
} else {
System.out.println(year + " is a leap year.");
}
} else {
System.out.println(year + " is not a leap year.");
}
scanner.close();
}
}
Variable name Data Type of the Variable Purpose of the Variable
year int To store the value
PROGRAM 14-
Write a program using Java language to check whether a
person is eligible to vote or not.
import java.util.Scanner;
scanner.close();
}
}
PROGRAM 15-
Write a program using Java language to display a name five
times.
public class NamePrinter
{
public static void main(String[] args)
{
String name = "John";
for (int i = 1; i <= 5; i++)
System.out.println(name);
}
}
}
Variable name Data Type of the Variable Purpose of the Variable
name string To store value
i int To use in for loop
PROGRAM 16 –
Write a program using Java language to convert a given
Centigrade temperature into Fahrenheit
import java.util.Scanner;
public class TemperatureConverter
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
PROGRAM 17-
Write a program using Java language to input the length
and width of a rectangle and then find the perimeter of this
rectangle.
import java.util.Scanner;
public class RectanglePerimeterCalculator
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the length of the rectangle: ");
scanner.close();
}
}
Variable name Data Type of the Variable Purpose of the Variable
length doule To store lenght
breadth double To store breadth
perimeter double To find the perimeter
PROGRAM 18-
Write a program using Java language to enter the number of
units consumed by a family in one month and then calculate
the Electricity bill at the rate of 5 rupees per unit.
import java.util.Scanner;
scanner.close();
}
}
Variable name Data Type of the Variable Purpose of the Variable
unit Int To store the units
consumed
billAmount double To calculate the
electricity bill
PROGRAM 19 –
Write a program using Java language to input the marks of
a student in three subjects out of 100 and then calculate the
percentage of his marks in each of the three subjects.
import java.util.Scanner;
scanner.close();
}
}
Variable name Data Type of the Variable Purpose of the Variable
Subject 1 Int To store marks
Subject 2 Int To store marks
Subject 3 Int To store marks
Subject 1 Percentage double To calculate percentage
Subject 2 Percentage double To calculate percentage
Subject 3 Percentage double To calculate percentage
PROGRAM 20-
Write a program using Java language to convert given
meters into centimeters.
import java.util.Scanner;
public class MeterToCentimeterConverter
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the length in meters: ");
scanner.close();
}
}
Variable name Data Type of the Variable Purpose of the Variable
Metre double To store the value
centimeter double To convert m into cm