Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

JAVA FUNDAMENTAL LAB

CAP2001L

School of Engineering and Sciences


Department of Computer Science and Engineering
Submitted By
Student Name Utkarsh Kumar
Roll No 210160212015
Programme BCA
Section/Group T1
Department Computer Science and Engineering
Session/Semester 2021-22/4th Semester
Submitted To
Faculty Name Ms. Savita Dagar

G D Goenka University
Gurgaon, Haryana
1|Page Utkarsh | BCA |T1
Aim the Experiment S
i
g
n
a
t
u
r
e
/
D
a
t
e

2|Page Utkarsh | BCA |T1


EXPERIMENT 1
Aim: Write a java program for addition of two number.
Input:
class Main {

public static void main (String [] args) {

int first = 10;


int second = 20;

// add two numbers


int sum = first + second;
System.out.println("Sum of First and Second number= “+ sum);
}
}

3|Page Utkarsh | BCA |T1


Output:

EXPERIMENT 2

Aim: Write a java program to check given number is Even or Odd.


Input:
public class EvenOdd {
public static void main(String[] args) {
int num=4;

if(num % 2 == 0)
System.out.println(num + " is even");
else
System.out.println(num + " is odd");
}
}
Output:

4|Page Utkarsh | BCA |T1


EXPERIMENT 3

Aim: Write a java program to reverse the given number.


Input:
public class Main {
public static void main (String [] args) {

int num = 1234;


int reversed = 0;

System.out.println("Original Number: " + num);

while (num! = 0) {
int digit = num % 10;
reversed = reversed * 10 + digit;

5|Page Utkarsh | BCA |T1


num =num/10;
}
System.out.println("Reversed Number: " + reversed);
}
}

Output:

EXPERIMENT 4

Aim: Write a java program to find greater number between two number.
Input:
public class main
{
public static void main (String[]args)
{
int a=5;
int b=8;
if(a>b)
System.out.println ( "a is greater");
else
System.out.println ( "B is greater");

6|Page Utkarsh | BCA |T1


}
}
Output:

EXPERIMENT 5

Aim: Write a java program to find greater number between three number.
Input:
public class Main
{
public static void main (String [] args)
{
int a=5;
int b=8;
int c=2;
if(a>b&&a>c)
System.out.println (“a is greater");
else if(b>a&&b>c)
System.out.println (“B is greater");

7|Page Utkarsh | BCA |T1


else
System.out.println (“C is greater");
}
}
Output:

EXPERIMENT 6

Aim: Write java program for weekdays using Switch Statement.


Input:

public class days {


public static void main(String[] args) {
int x=7 ;
switch(x) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");

8|Page Utkarsh | BCA |T1


break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
System.out.println("TGIF!");
break;
case 6:
System.out.println("Saturday");
break;
case 7:
System.out.println("Sunday");
break;
default:
System.out.println("Invalid day number.");
break;
}
}
}

Output:

9|Page Utkarsh | BCA |T1


EXPERIMENT 7

Aim: Write following java program using Switch Statement.


 Area of rectangle
 Area of circle
 Area of Square
Input:
class Main
{
public static void main(String[] args)
{
int operator=2;
int length=10;

10 | P a g e Utkarsh | BCA |T1


int width=4;
int a=4;
int r=2;
int pie=22/7;
int result;
switch (operator)
{
case 1:
result=length*width;
System.out.println("Area of rectangle= "+result);
break;
case 2:
result=pie*r*r;
System.out.println("Area of circle= "+result);
break;

case 3:
result=a*a;
System.out.println("Area of square= "+result);
break;
default:
System.out.println("Invalid operator..");
break;
}
}
}

11 | P a g e Utkarsh | BCA |T1


Output:

12 | P a g e Utkarsh | BCA |T1

You might also like