Computer Project
Name- Shaurya Rautela
Class- 9 C
Roll No- 44
Personal Number – 18090
Topic – Java Programming
Acknowledgment
I would like to express my special thanks of gratitude to my teacher Mrs. A.
Bhagat as well as our principal Mr. C. McFarland who gave me the golden
opportunity to do this wonderful project on the topic Java Programming
which also helped me in doing a lot of research and I came to know about so
many new things I am really thankful to them.
Secondly I would also like to thank my parents and friends who helped me a
lot in finalizing this project within the limited time frame.
Write a program using Java language to
generate the sum of three different numbers.
public class sum
public static void main(String[] args) {
//input can be taken using the Scanner class too
int a=Integer.parseInt(args[0]);
//input in this method can be passed in arguments when executing the program
int b=Integer.parseInt(args[1]);
int c=Integer.parseInt(args[2]);
int sum=a+b+c;
System.out.println("Sum of the numbers- "+sum);
}
Variable Data Type Description
1 a integer To store the first number
2 b Integer To store the second number
3 c Integer To store the third number
To store the sum of the first three
4 sum integer
numbers
Write a program using Java language to
generate the cube of first five even numbers
using while loop
public class cubeloop
public static void main(String[] args) {
int i=0;
while(i<=10){
System.out.println("The cube of "+i+" is "+i*i*i);
i+=2;
Variable Data Type Description
1 i integer To iterate the loop
Write a program using Java language to
generate the square of a given number
import java.util.*;//to import the scanner class
public class square
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter the number -");
int a=s.nextInt();
System.out.println("Square of "+a+" is "+a*a);
Variable Data Type Description
1 s Scanner To declare the Scanner class to take input
2 a Integer To store the input number
Write a program using Java language to
generate the cube of a given number
import java.util.*;
public class cube
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter the number -");
int a=s.nextInt();
System.out.println("Cube of "+a+" is "+a*a*a);
Variable Data Type Description
1 s Scanner To declare the Scanner class to take input
2 a Integer To store the input number
Write a program using Java language to check
whether a given number is even or odd.
import java.util.*;
public class oddeven
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter the number -");
int a=s.nextInt();
/* To check whether odd or even we check if number is divisible by 2
In order to do that we check that if remainder if divided by 2 is zero or not */
if (a%2==0){
//if zero it is divisible thus even
System.out.println(a+" is an even number");
}else{
//if remainder is not zero; it is not divisible by two thus it is odd
System.out.println(a+" is an odd number");
}
Variable Data Type Description
1 s Scanner To declare the Scanner class to take input
2 a Integer To store the input number
Write a program using Java language to check
whether a given number is positive, negative or
zero
//using Scanner class to take input
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter the number -");
int a=s.nextInt();
//To check whether negative or positive we check if number is smaller than zero
if (a>0){
//if zero it is divisible thus even
System.out.println(a+" is a positive number");
}else if(a==0) {
//if a number is equal to zero we simply print this
System.out.println(a+" is neither negative nor positive and it is zero");
}else{
//if smaller than zero it is negative
System.out.println(a+" is a negative number");
}
Variable Data Type Description
1 s Scanner To declare the Scanner class to take input
2 a Integer To store the input number
Write a program using Java language to
generate the table of a given number up to
count ten
//using Scanner class to take input
import java.util.*;
public class Main
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter the number -");
int a=s.nextInt();
for (int i =1;i<=10 ;i++ ){
System.out.println(a+" X "+i+" = "+a*i);
//using "X" for showing the multiplication sign because there are not any specific symbol
}
Variable Data Type Description
1 s Scanner To declare the Scanner class to take input
2 a Integer To store the input number
3 I Integer To iterate the loop
Write a program using Java language to
generate first ten even numbers
public class evennum
public static void main(String[] args) {
System.out.println("The first ten even numbers are -");
//using for loop
for (int i =0;i<=20;i+=2 ){
System.out.println(i);
Variable Data Type Description
1 i Integer To iterate the loop
Write a program using Java language to
generate first five odd numbers
public class oddnum
public static void main(String[] args) {
System.out.println("The first five odd numbers are -");
//using for loop
for (int i =1;i<=9;i+=2 ){
System.out.println(i);
Variable Data Type Description
To iterate the loop and also act as the
1 i Integer
numbers to be printed
Write a program using Java language to
generate the square of first ten natural
numbers
public class squaretwo
public static void main(String[] args) {
for (int i =1;i<=10;i++){
System.out.println("Square of "+i+" is "+i*i);
Variable Data Type Description
To iterate the loop and also act as the
1 i Integer
natural numbers
Write a program using Java language to print
the days of the week using switch case
statement
import java.util.*;//import the scanner class
public class week{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter the number of the day of the week -");
int a=s.nextInt();
switch(a){
case 1:
System.out.println("Sunday");
break;
case 2:
System.out.println("Monday");
case 3:
System.out.println("Tuesday");
break;
case 4:
System.out.println("Wednesday");
case 5:
System.out.println("Thursday");
break;
case 6:
System.out.println("Friday");
case 7:
System.out.println("Saturday");
break;
default:
System.out.println("Invalid number");
Variable Data Type Description
1 s Scanner To declare the Scanner class to take input
To store the input number of the days of
2 a Integer
week
Write a program using Java language to input
twenty numbers and print those numbers that
are divisible by 3
public class divisthree{
public static void main(String[] args) {
int a;//for storing the integers
for (int i=0;i<args.length;i++){
//args.length is the number of arguments passed when the executing the program
a=Integer.parseInt(args[i]);
//input can be made by typing the integers in the argument when running the program
if (a%3==0){
System.out.println(args[i]+" is divisible by 3");
Variable Data Type Description
1 a Integer To Store the numbers
To iterate the loop and also act as the
2 i Integer
positions in the args array
Write a program using Java language to input
a year in four digit and test whether it is a leap
year or not.
import java.util.*;//to import the Scanner class
public class Main
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter the year -");
int a=s.nextInt();
//to check if its leap year or not we see if it is divisible by two or not
if(a%4==0){
System.out.println(a+" is a leap year");
}else{
System.out.println(a+" is not a leap year");
}
Variable Data Type Description
1 s Scanner To declare the Scanner class to take input
To store the input number of the days of
2 a Integer
week
Write a program using Java language to input
the marks of five subjects of a student out of
100 and display his average marks of all the
five subjects.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter the marks out of 100");
//each variable to store the marks of respective subjects
System.out.println("Enter the marks of Mathematics -");
int math_num=s.nextInt();
System.out.println("Enter the marks of Physics -");
int phys_num=s.nextInt();
System.out.println("Enter the marks of Chemistry -");
int chem_num=s.nextInt();
System.out.println("Enter the marks of Hindi -");
int h_num=s.nextInt();
System.out.println("Enter the marks of English -");
int eng_num=s.nextInt();
//to store the averge marks
int avg=(math_num+phys_num+chem_num+h_num+eng_num)/5;
System.out.println("The Average marks of all five subjects is - "+avg) } }
Variable Data Type Description
1 eng_num integer To store the first number
2 hindi_num Integer To store the marks of Hindi
3 math_num Integer To store the marks of maths
4 phys_num integer To store the marks of physics
5 chem_num Integer To store the marks of Chemistry
6 s Scanner To declare the Scanner Class to take input
7 avg Integer To store the average of the five subjects
Write a program using Java language to
display the word “COMPUTER” five times
public class Main
public static void main(String[] args) {
//using for loop
for (int i=1;i<=5 ;i++ ){
System.out.println("COMPUTER");
Variable Data Type Description
1 i Integer To iterate the loop