Java Lab Experiments
Java Lab Experiments
Aim:
else
System.out.println(c+" is the largest number");
}
}
Output
Enter the first number:
10
Enter the second number:
5
Enter the third number:
6
10 is the largest Number
EXP 2
Aim:
Program:
import java.util.Scanner;
public class cuboid {
public static void main(String[] args)
{
int volume,length,width,height;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Length ");
length=sc.nextInt();
System.out.println("Enter the Width ");
width=sc.nextInt();
System.out.println("Enter the Height ");
height=sc.nextInt();
volume=length*width*height;
System.out.println("Volume= "+volume);
}
Output:
EXP 5
Aim:
Write a program to input the name and marks in 3 subjects of a student.
Display the total mark and the average marks.
Program:
import java.util.Scanner;
public class LabExperiment1
{
public static void main(String[] args)
{
String name;
int m[]=new int[3];
System.out.println("Enter the name ");
Scanner sc=new Scanner(System.in);
name=sc.next();
System.out.println("Enter 3 marks ");
for(int i=0;i<3;i++)
{
m[i]=sc.nextInt();
}
//Calculate total and average
int tot=0;
float avg;
for(int i=0;i<3;i++)
{
tot=tot+m[i]; //m[0]+m[1]+m[2];
}
avg=tot/3;
System.out.println("Name = "+name);
System.out.println("Marks are "+m[0]+","+m[1]+" , "+m[2]);
System.out.println("TOTAL MARK = "+tot);
System.out.println("AVERAGE MARK = " +avg);
}
}
OUTPUT
Exp:6
Aim:
OUTPUT
EXP 7
Aim:
Output:-
Enter the element to search
67
Element found at position 5s
Exp 8
Aim:
Program:
import java.util.Scanner;
public class Employee {
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the NUMBER of Employees ");
int n=sc.nextInt();
String empname[]=new String[n];
double basicsalary[]=new double [n];
double HRA[]=new double [n];
double DA[]=new double [n];
double netsalary[]=new double [n];
for(int i=0;i<n;i++)
{
System.out.println("Enter the "+(i+1) +"employee name ");
empname[i]=sc.next();
System.out.println("Enter the basic salary of "+(i+1)+" employee ");
basicsalary[i]=sc.nextInt();
if(basicsalary[i] >= 70000)
{
HRA[i]=(0.05*basicsalary[i]);
DA[i]=(0.1*basicsalary[i]);
}
else
{
HRA[i]=(.03*basicsalary[i]);
DA[i]=1000;
}
netsalary[i]=basicsalary[i]+HRA[i]+DA[i];
}
System.out.println(" \n**********Employee details are**********\n ");
for(int i=0;i<n;i++)
{
System.out.println("Employename : "+empname[i]);
System.out.println("Employee basic salary : "+basicsalary[i]);
System.out.println("HRA : "+HRA[i]);
System.out.println("DA : "+DA[i]);
System.out.println("netsalary : "+netsalary[i]);
}
}
}
OUTPUT:
Enter the NUMBER of Employees
2
Enter the 1employee name
PRANAV
Enter the basic salary of 1 employee
45000
Enter the 2employee name
KALYANI
Enter the basic salary of 2 employee
35000
Aim:
}
public void add()
{
System.out.println("sum ="+(a+b));
}
public void diff()
{
System.out.println("diff="+(a-b));
}
public void mul()
{
System.out.println("mul="+(a*b));
}
public void div()
{
System.out.println("div="+(a/b));
}
public static void main(String[] args)
{
int ch;
Scanner SC= new Scanner(System.in);
calculator ob=new calculator();
for(;;)
{
System.out.println("1.sum");
System.out.println("2.difference");
System.out.println("3.product");
System.out.println("4.division");
System.out.println("5.exit 0");
System.out.println("********");
System.out.println(" enter your choice");
ch=SC.nextInt();
switch(ch)
{
case 1: ob.read();ob.add();break;
case 2: ob.read();ob.diff();break;
case 3: ob.read();ob.mul();break;
case 4: ob.read();ob.div();break;
case 5: System.exit(0);
default: System.out.println("wrong choice");break;
}
}
}
}un:
1.sum
2.difference
3.product
4.division
5.exit 0
********
enter your choice
1
Object array
Factorial un:
1.sum
2.difference
3.product
4.division
5.exit 0
********
enter your choice
1
EXP 10
Aim:
Exp 11:
Aim:
Write a program to check whether the entered number is odd or
even using static user defined method.
Program:
import java.util.Scanner;
public class EvenOdd
{
public static void main (String args[])
{
//creating Scanner class object
Scanner scan=new Scanner(System.in);
System.out.print("Enter the number: ");
//reading value from user
int num=scan.nextInt();
//method calling
findEvenOdd(num);
}
//user defined method
public static void findEvenOdd(int num)
{
//method body
if(num%2==0)
System.out.println(num+" is even");
else
System.out.println(num+" is odd");
}
}
OUTPUT
Enter the number: 12
s Enter the number: 99
99 is odd even s even
******************************************************************************************************************
EXP 12
Aim:
Write a Program to demonstrate having the main
method in another class
Program:
OUTPUT
0
Null
*****************************************************************************************
EXP 13
Aim:
import java.util.Scanner;
public class vowelconso {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a character: ");
char ch = scanner.next().charAt(0);
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch
== 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
System.out.println(ch + " is a vowel.");
} else {
System.out.println(ch + " is a consonant.");
}
} else {
System.out.println("Invalid input. Please enter an alphabet.");
}
Enter a character:
a
a is a vowel.
Enter a character:
b
b is a consonant.
EXP 14
Aim:
class Stringdemo {
public static void main(String[] args) {
String myString = "Welcome to icsk senior";
System.out.println("UpperCase: " +
myString.toUpperCase());
System.out.println("LowerCase: " +
myString.toLowerCase());
System.out.println("position: " + myString.charAt(5));
System.out.println("join: " + myString.concat("\t Salmiya"));
System.out.println("contain: " + myString.contains("or"));
System.out.println("Endswith: " + myString.endsWith("ni"));
System.out.println("Compaire: " + myString.equals("senior"));
System.out.println("equalbutignorecase: " +
myString.equalsIgnoreCase("Welcome to icsk senior"));
}
}
Output :
UpperCase: WELCOME TO ICSK SENIOR
LowerCase: welcome to icsk senior
position: m
join: Welcome to icsk senior Salmiya
contain: true
Endswith: false
Compaire: false
equalbutignorecase: true
After 14 practicals
sql query :
15Flight table with query