Untitled
unknown
plain_text
a year ago
4.2 kB
37
Indexable
Never
LAB 1A: Program to check x and y values using if statement and displaying message whether x is greater than y package LabPgm1; public class Pgm1 { public static void main(String args[]) { int x=8, y=3; System.out.println("X = " +x); System.out.println("Y = " +y); if( x > y ) System.out.println("X is greater than Y"); else System.out.println("Y is greater than X"); } } OUTPUT: X = 8 Y = 3 X is greater than Y LAB 2A: Program to list the factorial of the numbers from 1 to 10 using while loop package LabPgm2; public class Pgm2 { public static void main(String[] args) { int fact, i, j; for(i=1;i<=10;i++) { System.out.print("\nFactorial of " + i + " is: "); fact=1; j=1; while(j<=i) { fact = fact * j; j++; } System.out.print(fact); } } } OUTPUT: Factorial of 1 is: 1 Factorial of 2 is: 2 Factorial of 3 is: 6 Factorial of 4 is: 24 Factorial of 5 is: 120 Factorial of 6 is: 720 Factorial of 7 is: 5040 Factorial of 8 is: 40320 Factorial of 9 is: 362880 Factorial of 10 is: 3628800 LAB 3A: Program to find the area and circumference of the circle by accepting the radius from the user package LabPgm3; import java.util.*; public class Pgm3 { public static void main(String args[]) { double radius, area, circum; Scanner in = new Scanner(System.in); System.out.println("Enter radius value: "); radius = in.nextDouble(); area=Math.PI * radius * radius; circum = 2 * Math.PI * radius; System.out.println("Area = " +area); System.out.println("Circumference = " +circum); } } OUTPUT: Enter radius value: 2.6 Area = 21.237166338267002 Circumference = 16.336281798666924 LAB 4A: Program to add two integer and two float numbers. Use function overloading package LabPgm4; public class AddDemo { int a=2, b=6, res; double c=3.5, d=5.6, res1; void addInt() { res = a+b; System.out.println("Addition of default Integer values" +a+ " and " +b+ " is: " + res); } void addInt(int x, int y) { a=x; b=y; res = a+b; System.out.println("Addition of Integer parameters values "+a+" and "+b+" is: "+res); } void addFloat() { res1 = c+d; System.out.println("\nAddition of default Float values " +c+ " and "+d+ " is: " +res1); } void addFloat(double x, double y) { c=x; d=y; res1 = c+d; System.out.println("Addition of Float parameters values "+c+" and "+d+" is: " +res1); } } package LabPgm4; public class Pgm4 { public static void main(String[] args) { AddDemo ad = new AddDemo(); Scanner in = new Scanner(System.in); int a,b; double c,d; System.out.println("Enter 2 integer values" ); a=in.nextInt(); b=in.nextInt(); System.out.println("Enter 2 float values" ); c=in.nextDouble(); d=in.nextDouble(); ad.addInt(); ad.addInt(a,b); ad.addFloat(); ad.addFloat(c,d); } } OUTPUT: Enter 2 integer values 3 6 Enter 2 float values 2.3 6.5 Addition of default Integer values 2 and 6 is: 8 Addition of Integer parameters values 3 and 6 is: 9 Addition of default Float values 3.5 and 5.6 is: 9.1 Addition of Float parameters values 2.3 and 6.5 is: 8.8 LAB 5A: Program to perform arithmatic operations by extending the classes package LabPgm5; import java.util.*; public class AddSub { int a, b; int add, sub; Scanner in = new Scanner(System.in); void getdata() { System.out.println("Enter a value:"); a= in.nextInt(); System.out.println("Enter b value:"); b= in.nextInt(); } void add1() { add = a + b; System.out.println("Addition: "+add); } void sub1() { sub = a - b; System.out.println("Subtraction: "+sub); } } package LabPgm5; public class MulDiv extends AddSub { int mul; double div; void mul1() { mul = a * b; System.out.println("Multiplication: "+mul); } void div1() { div = a / b; System.out.println("Division: "+div); } } package LabPgm5; public class Pgm5 { public static void main(String[] args) { MulDiv obj = new MulDiv(); obj.getdata(); obj.add1(); obj.sub1(); obj.mul1(); obj.div1(); } } OUTPUT: Enter a value: 6 Enter b value: 2 Addition: 8 Subtraction: 4 Multiplication: 12 Division: 3.0