Академический Документы
Профессиональный Документы
Культура Документы
HITESH SALUJA
E.NO. A2305208338 ROLL NO. 536 CS-3(Y)
CONTENTS
S.NO
TOPIC
DATE
REMARK S
a=Integer.parseInt(arg[0]); b=Integer.parseInt(arg[1]); c=Integer.parseInt(arg[2]); if((a>b) && (a>c)) System.out.println("greatest :"+a); else if((b>a) && (b>c)) System.out.println("greatest :"+b); else System.out.println("greatest :"+c); } }
Output:
C:\jdk1.3\bin>java hiteshgreatest9 1 6 greatest :9
class hitfactorial{ public static void main(String arg[]) { int fact=1,num; num=Integer.parseInt(arg[0]); for(int i=num;i>=1;i--) { fact=fact*i; }
System.out.println("factorial="+fact); } }
public class sumavg{ public static void main(String a[]) { int num[]={4,8,2,1,5}; int l=num.length; int x,s=0; float avg; System.out.println("numbers inside num"); for(x=0;x<l;x++) { System.out.println(" "+num[x]); } System.out.println("Sum= ");
for(x=0;x<l;x++) { s+=num[x]; } System.out.println(" "+s); avg=s/5; System.out.println("Average="+avg); } } OUTPUT: C:\jdk1.3\bin>java sumavg numbers inside num 4 8 2 1 5 sum=20 average=4
class csstudent{ int r.no,marks1,marks2,marks3; String name; void getdata(int r.no, int marks1, int marks2, int marks3, String name) { this.r.no=r.no; this.marks1=marks1; this.marks2=marks2; this.marks3=marks3; this.name=name; } int setdata() { return((marks1+marks2+marks3)/3); } void display() {
System.out.println("CS Student record"); System.out.println("Roll no=:"+r.no); System.out.println("subject1="+marks1); System.out.println("subject2=+marks2); System.out.println("subject3="+marks3); System.out.println("Average="+setdata()); System.out.println("Name "+name); }} class cs{ public static void main(String a[]) { csstudent stud=new csstudent(); stud.getdata(536,33,98,88,"ram"); stud.display(); } } }
OUTPUT: C:\jdk1.3\bin>java cs CS Student record Roll no=536 Subect1=33 Subect2=98 Subect3=88 Average=73 Name ram
import java.lang.*; class employee { public static void main(String arg[]) { int salary=12000; if(arg[0].compareToIgnoreCase("ceo")==0) { salary += Integer.parseInt(arg[1]); } else if(arg[0].compareToIgnoreCase("manager")==0) { salary += Integer.parseInt(arg[1]); } else if(arg[0].compareToIgnoreCase("employee")==0) { salary += Integer.parseInt(arg[1]); } System.out.print(salary); } }
class bankrecord { String name; char type; static double bal; bankrecord(String name,char type,double bal) { this.name=name; this.type=type; this.bal=bal; } void deposit(double d) { bal=bal+d; System.out.println("Balance after deposit:"+bal); } void withdraw(double amt) { if(bal>500) { bal=bal-amt; System.out.println("Balance after withdrawal:"+bal); } else System.out.println("Sorry, You cannot withdraw"); } void display() { System.out.println("Name:"+name);
System.out.println("Type of account:"+type); System.out.println("Net Balance:"+bal); } } class record { public static void main(String a[]) { bankrecord br=new bank("raghav",'savings',4400.0); br.display(); br.deposit(1000.0); br.withdraw(1900.0); System.out.println("\n\nCustomer Information"); br.display(); } } OUTPUT: C:\jdk1.3\bin>java record Name:raghav Type of account:savings Net Balance:4400.0 Balance after deposit:5500.0 Balance after withdrawal:3500.0 Customer information Name:raghav Type of account:savings Net Balance:3500.0
class csstudent{ int r.no,marks1,marks2,marks3; String name; void getdata(int r.no, int marks1, int marks2, int marks3, String name) { this.r.no=r.no; this.marks1=marks1; this.marks2=marks2; this.marks3=marks3; this.name=name; } int setdata() { return((marks1+marks2+marks3)/3); } void display() { System.out.println("CS Student record"); System.out.println("Roll no=:"+r.no); System.out.println("subject1="+marks1); System.out.println("subject2=+marks2); System.out.println("subject3="+marks3); System.out.println("Average="+setdata()); System.out.println("Name "+name); }} class cs{ public static void main(String a[]) { csstudent stud=new csstudent(); stud.getdata(536,33,98,88,"ram"); stud.display(); } } }
OUTPUT: C:\jdk1.3\bin>java cs CS Student record Roll no=536 Subect1=33 Subect2=98 Subect3=88 Average=73 Name ram
class differentareas{ double area(int length,int breadth){ System.out.println("\nLength of rectangle:"+length); System.out.println("Breadth of rectangle:"+breadth); return length*breadth; } double area(double radius){ System.out.println("\nRadius of circle:"+radius); return 3.14*radius*radius; } double area(int side){ System.out.println("\nSide of square:"+side); return side*side; } } class main{ public static void main(String a[]) { double r,c,sq; differentareas s=new differentareas(); sq=s.area(5); System.out.println("Area of square:"+sq); c=s.area(2.2); System.out.println("Area of circle:"+c); r=s.area(10,13); System.out.println("Area of rectangle:"+r); } }
Radius of circle:2.2 Area of circle:15.197 Length of rectangle:10 Breadth of rectangle:13 Area of rectangle:130
class employee{ int id; String name; String desg; int sal;
void getdata(int id,String name,String desg,int sal){ this.name=name; this.id=id; this.desg=desg; this.sal=sal; } void display(){ System.out.println("ID No.: "+id); System.out.println("Name: "+name); System.out.println("Designation: "+desg); System.out.println("Salary: "+sal); } } class emp{ public static void main(String a[]){ employee c = new employee(); c.getdata(1,"hitesh","ceo", 80000); c.display(); employee m = new employee(); m.getdata(11,"atul","manager", 40000); m.display(); employee w = new employee(); w.getdata(98,"rakesh","worker", 20000); w.display(); } } OUTPUT: C:\jdk1.3\bin>java emp ID No.: 1 Name: raghav Designation: ceo Salary: 80000 ID No.: 11 Name: atul Designation: manager Salary: 40000 ID No.: 98 Name: rakesh Designation: worker Salary: 20000
class hitesh1 { public static void main(String arg[]) { try { int a= arg.length; System.out.print(a); int b=42/a; int c[]={1}; c[42]=99;
} catch(ArithmeticException e) { System.out.print("Divide by zero" + e); } catch(ArrayIndexOutOfBoundsException e) { System.out.print("Array Index Higher" +e); System.out.print("After try catch"); } } }