











































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA LAB MANUAL JAVA
Typology: Cheat Sheet
1 / 51
This page cannot be seen from the preview
Don't miss anything!
Subject In-charge : Nidhi Gour
1. Operators and Expressions a. To write a java program to find the area of rectangle b. To write a java program to find the result of the following expressions i) (a<<2) + (b>>2) ii) (b>0) iii) (a+b*100) / iv) a & b Assume a=10 and b= c. To write a java program to print the individual digits of a 3 digit number. 2. Decision Making Statements a. write a java program to read two integers and print the larger number followed by the words “is larger “If the numbers are equal print the message “These numbers are equal”. b.To write a java program to read an integer and find whether the number is odd or even c. To write a java program find the biggest of three integers. 3. Looping Statements a. To write a java program to find the sum of digits of a given number b. To write a java program to find the first 15 terms of Fibonacci sequence. c. To write a java program to print the Armstrong numbers. 4. Array a. To write a java program to find the largest and smallest number in an array.
a. To write a java program to create a package for Book details giving Book name, Author name, price and year of publishing.
11. Applets & AWT a. To write a java applet program to change the color of a rectangle using scroll bars to change the value of red, green and blue b. To write an applet program for creating a simple calculator to perform Addition, subtraction, Multiplication and Division using Button, Label and TextField component. 12. Exception Handling a. To write a java program to catch more than two exception b. To write a java program to create our exception subclass that throws exception if the sum of two integers is greater than 99. 13. Multithreading a. To write a java program for generating two threads, one for generating even number and one for generating odd number.
(A) Aim: To write a java program to find the area of rectangle Program: /* Program to find area of rectangle / import java.util.; class AreaRect { public static void main(String args[]) { int len,bre,area; Scanner sc= new Scanner(System.in); len=sc.nextInt(); bre=sc.nextInt(); area=len*bre; System.out.println("Length of Rectangle ="+len); System.out.println("Breadth of Rectangle ="+bre); System.out.println("Areaof Rectangle ="+area); } } Output: D:\java>javac AreaRect.java D:\java>java AreaRect 12 6 Length of Rectangle = Breadth of Rectangle = Areaof Rectangle = D:\java>
(C)Aim: To write a java program to print the individual digits of a 3 digit number. Program: /* Program to print the individual digits of a 3-digit number / import java.util.; class Digits { public static void main(String args[]) { int n,r; Scanner sc=new Scanner(System.in); n=sc.nextInt(); System.out.println("The number is "+ n); System.out.println("The digits in the number are"); System.out.println("**************************"); r=n%10; /* Find the one's digit / System.out.println(r); n=n/10; / Reduce the number / r=n%10; / Find the ten's digit / System.out.println(r); n=n/10; / Reduce the number / r=n%10; / Find the hundred'slast digit */ System.out.println(r); } } Output: D:\java>javac Digits.java D:\java>java Digits 729 The number is 729 The digits in the number are
9 2 7 D:\java>
(A)Aim: To write a java program to read two integers and print the larger number followed by the words “is larger”. If the numbers are equal print the message “These numbers are equal”. Program: /* Program to find the largest number / import java.util.; class Large { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int a,b; System.out.print("Enter the value of a:"); a=sc.nextInt(); System.out.print("Enter the value of b:"); b= sc.nextInt(); System.out.println("a="+a+"\t\tb="+b); if(a==b) System.out.println("These numbers are equal"); else if(a>b) System.out.println(a+ " is larger"); else System.out.println(b+" is larger"); } } Output : D:\java>javac Large.java D:\java>java Large Enter the value of a: Enter the value of b: a=45 b= 45 is larger
(C)Aim: To write a java program find the biggest of three integers Program: /* Program to find the biggest of three integers / import java.util.; class Big { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int a,b,c; System.out.print("Enter number 1:"); a=sc.nextInt(); System.out.print("Enter number 2:"); b=sc.nextInt(); System.out.print("Enter number 3:"); c=sc.nextInt(); System.out.println("a="+a+"\t\tb="+b+"\t\tc="+c); if (a>b) { if(a>c) System.out.println(a+" is the biggest number"); else System.out.println(c+" is the biggest number"); } else { if(b>c) System.out.println(b+" is the biggest number"); else System.out.println(c+" is the biggest number"); } } } Output: D:\java>javac Big.java D:\java>java Big Enter number 1: Enter number 2: Enter number 3:
a=4 b=5 c= 5 is the biggest number
(B)Aim: To write a java program to find the first 15 terms of Fibonacci sequence. Program: /* First 15 terms of Fibonacci sequence */ class Fibo { public static void main(String args[]) { int f1=0,f2=1,f3; System.out.println("Fibonacci sequence "); System.out.println("**************"); System.out.print("\t"+f1+"\t"+f2); for(int i=3;i<=15;i++) { f3=f1+f2; System.out.print("\t"+f3); f1=f2; f2=f3; } } } Output: D:\java>javac Fibo.java D:\java>java Fibo Fibonacci sequence
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
(C)Aim: To write a java program to print the Armstrong numbers. Note: Armstrong numbers are the three digit numbers whose sum of cubes of the digits of the number is equal to the number itself. Example: 153= 3
3
3 = 1 + 125 +27 =153 is an Armstrong number Program: /* Program to print the Armstrong numbers/ import java.io.; class Armstrong { public static void main(String args[])throws IOException { System.out.println("Armstrong numbers"); System.out.println("*****************"); for(int i=100;i<=999;i++) { int n=i; int sum=0; while(n!=0) { int r=n%10; sum=sum+(int)Math.pow(r,3); n=n/10; } if(sum==i) System.out.println(i); } } } Output: D:\java>javac Armstrong.java D:\java>java Armstrong Armstrong numbers
153 370 371
Aim: To write a java program to find the largest and smallest number in an array. Program: /* Program to find the biggest and smallest number in the array / import java.io.; class ArrBig { public static void main(String args[])throws IOException { int a[]=new int[20]; int n,big,small; BufferedReader din=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter number of terms in the array:"); n=Integer.parseInt(din.readLine()); System.out.println("Enter array element:"); for(int i=0;i<n;i++) { System.out.print("a["+i+"]:"); a[i]=Integer.parseInt(din.readLine()); } big=a[0]; small=a[0]; for(int i=1;i<n;i++) { if(a[i]>big) big=a[i]; if(a[i]<small) small=a[i]; } System.out.println("\nThe elements in the array"); System.out.println("***********************"); for(int i=0;i<n;i++) System.out.print("\t"+a[i]); System.out.println("\nThe biggest element in the array is "+big); System.out.println("The smallest element in the array is "+small); } } Output: D:\java>javac ArrBig.java D:\java>java ArrBig Enter number of terms in the array:
Enter array element: a[0]: a[1]: a[2]: a[3]: a[4]: The elements in the array
56 78 12 4 89 The biggest element in the array is 89 The smallest element in the array is 4 D:\java>
The given name is Java Programming The length of name is The character 'a' is present in the locations 1 3 10 The character 'a' is present 3 times D:\java>
(A)Aim: To write a java program to create a StringBuffer object and illustrate how to append characters and to display the capacity and length of the string buffer Program: /* Program to create a StringBuffer object and illustrate how to append characters. Display the capacity and length of the string buffer.*/ class StringBufferDemo { public static void main(String args[]) { StringBuffer s1=new StringBuffer("Java"); System.out.println("The data in the string buffer:"+ s1); System.out.println("Capacity of the Buffer :"+s1.capacity()); System.out.println("Length of buffer:"+s1.length()); s1.append("Programming"); System.out.println("The data in the StringBuffer after appending characters is "+s1); } } Output: D:\java>javac StringBufferDemo1.java D:\java>java StringBufferDemo The data in the string buffer:Java Capacity of the Buffer : Length of buffer: The data in the StringBuffer after appending characters is JavaProgramming D:\java>