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

Java Output

The document contains multiple Java programming examples demonstrating various concepts such as banking operations, shape area calculations using constructors, student marks calculation with inheritance, employee salary computation with interfaces, exception handling for age validation, and multithreading for multiplication tables. Each example includes a class structure, methods for user input, and output results. The outputs illustrate the functionality of the code snippets, showing how they operate in practice.

Uploaded by

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

Java Output

The document contains multiple Java programming examples demonstrating various concepts such as banking operations, shape area calculations using constructors, student marks calculation with inheritance, employee salary computation with interfaces, exception handling for age validation, and multithreading for multiplication tables. Each example includes a class structure, methods for user input, and output results. The outputs illustrate the functionality of the code snippets, showing how they operate in practice.

Uploaded by

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

EXP : 1(a)

import java.util.*;
class bank
{
float bamt,damt,wamt;
void get()
{
Scanner inp=new Scanner(System.in);
System.out.println("Enter Balance Amount: ");
bamt=inp.nextFloat();
}
void deposit()
{
Scanner inp=new Scanner(System.in);
System.out.println("Enter Deposit Amount: ");
damt=inp.nextFloat();
bamt=bamt+damt;
System.out.println("Current Balance: "+bamt);
}
void Withdrawal()
{
Scanner inp=new Scanner(System.in);
System.out.println("Enter Withdrawal Amount: ");
wamt=inp.nextFloat();
bamt=bamt-wamt;
System.out.println("Current Balance: "+bamt);
}
}
public class Psgbank {

public static void main(String[] args) {


bank b=new bank();
b.get();
b.deposit();
b.Withdrawal();
}
}

Output :

Enter Balance Amount:


10000
Enter Deposit Amount:
5000
Current Balance: 15000.0
Enter Withdrawal Amount:
2500
Current Balance: 12500.0
EXP : 1(b)

class shape
{
int sarea;
shape(int a)
{
sarea=a*a;
System.out.println("Area of Square: "+sarea);
}
shape(int l ,int b)
{
sarea=l*b;
System.out.println("Area of Rectangle: "+sarea);
}
}
public class Constructor {

public static void main(String[] args) {


shape s=new shape(7);
shape s1=new shape(9,10);
}
}

Output :

Area of Square: 49
Area of Rectangle: 90
EXP : 2(a)

import java.util.*;
class semester
{
int rno,m1,m2,m3;
void getmarks()
{
Scanner inp=new Scanner(System.in);
System.out.println("Enter Roll No: ");
rno=inp.nextInt();
System.out.println("Enter 1st subject marks: ");
m1=inp.nextInt();
System.out.println("Enter 2nd subject marks: ");
m2=inp.nextInt();
System.out.println("Enter 3nd subject marks: ");
m3=inp.nextInt();
}
}
class sports extends semester
{
int smark,total;
void getsports()
{
smark=10;
}
void calculate()
{
total=m1+m2+m3+smark;
System.out.println("Rollno: "+rno);
System.out.println("Total mark: "+total);
}
}
public class Student {

public static void main(String[] args)


{
sports s=new sports();
s.getmarks();
s.getsports();
s.calculate();
}
}
Output :

Enter Roll No:


23
Enter 1st subject marks:
63
Enter 2nd subject marks:
54
Enter 3nd subject marks:
71
Rollno: 23
Total mark: 198
EXP : 2(b)

import java.util.*;
class employee
{
float bpay,hra,da,pf;
void get()
{
Scanner inp=new Scanner(System.in);
System.out.println("Enter Basic Pay: ");
bpay=inp.nextFloat();
System.out.println("Enter HRA,DA,PF: ");
hra=inp.nextFloat();
da=inp.nextFloat();
pf=inp.nextFloat();
}
}
interface bonus
{
final int b=100;
}
class salary extends employee implements bonus
{
float gpay,npay;
void calculate()
{
get();
gpay=bpay+hra+da+b;
npay=gpay-pf;
System.out.println("Gross pay="+gpay);
System.out.println("Net pay="+npay);
}
}
public class Company {
public static void main(String[] args) {
salary s=new salary();
s.calculate();
}
}

Output :

Enter Basic Pay:


15000
Enter HRA,DA,PF:
5000
2500
2000
Gross pay=22600.0
Net pay=20600.0
EXP : 3

import java.util.*;
class invalidage extends Exception
{
public invalidage(String msg)
{
super(msg);
}
}
public class Customerexception {

public static void main(String[] args) {


int age;
try
{
Scanner inp=new Scanner(System.in);
System.out.println("Enter Age: ");
age=inp.nextInt();
if(age<18)
throw new invalidage("Age must be greater than 18 for vote");
else
System.out.println("Eligible to vote");
}
catch(invalidage e)
{
System.out.println("Caught Exception:"+e.getMessage());
}
}
}

Output :

Enter Age:
12
Caught Exception:Age must be greater than 18 for vote

Enter Age:
20
Eligible to vote
EXP : 4

class two extends Thread


{
public void run()
{
for(int i=1;i<=5;i++)
System.out.println(i+" x 2 = "+i*2);
}
}
class three extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
System.out.println(i+" x 3 = "+i*3);
}
}
class five extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
System.out.println(i+" x 5 = "+i*5);
}
}
public class Multiplication {
public static void main(String[] args) {
two t1=new two();
three t2=new three();
five t3=new five();
t1.start();
t2.start();
t3.start();
}
}
Output :

1x2=2
2x2=4
3x2=6
4x2=8
5 x 2 = 10
1x3=3
2x3=6
3x3=9
4 x 3 = 12
5 x 3 = 15
1x5=5
2 x 5 = 10
3 x 5 = 15
4 x 5 = 20
5 x 5 = 25

You might also like