Está en la página 1de 14

Sn. No. 1. 2.

Experiments WAP to split of a four digit numbers WAP to find the largest between three numbers using Ternary operators

3. 4.

WAP to find Xn without using pow () function WAP to perform Menu Driven Arithmetic operation

5. WAP to find Area of Circle, Rectangle and Triangle using different methods 6. 7. 8. WAP to perform Matrix Multiplication WAP to count frequency of a given letter in a String Write a program that accepts a shopping list of items from the command line and stores them in a vector. Also provide facility to perform following operations a) To delete an item in the list. b) To add an item at a specified location in the list. c) To add an item at the end of the list. d) To print the contents of the vector. WAP to implement multiple inheritance by using interface WAP to display volume of sphere and Hemisphere, make use of abstract class

9. 10.

11. 12.

WAP to display string using thread WAP to display Frame .The Frame should be titled as JAVA & the background Color should be set to yellow, display string at pixel location (50, 50) on a Frame

13. 14.

WAP to display Human face using applet WAP to load and display an image using applet

15.

WAP to find square of a given number using ActionListener

1.

class P7 { public static void main(String args[]) { int x = 1234, y, z; y = x /1000 ; System.out.println(" The digit in the Thousand's place = "+y); z = x % 1000; y = z /100; System.out.println("\n The digit in the Hundred's place = "+y); z = z % 100; y = z / 10; System.out.println("\n The digit in the Ten's place = "+y); y = z % 10; System.out.println("\n The digit in the Unit's place = "+y); } }

2.

import. java.*; class Largest { public static void main(String args[]) {

int a, b, c, big ; clrscr() ; System.out.println ("Enter three numbers : ") ; Scanner in = new scanner (); int a = in.nextInt(); int b = in.nextInt(); int c= in.nextInt(); big = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c) ; System.out.println ("\nThe biggest number is : %d" + big) ; } } } 3. // Compute x^n recursively. public class Recurse { /* precondition: This method computes x^n, where n is assumed to be nonnegative. A call to this method with negative n will cause the program to crash. postcondition: x^n has been returned. */

public static double power(double x, int n) { if (n == 0) // This is called the base case. The

return 1.0; // base case controls the depth of the // recursion, i.e., how many recursive // calls are made. return x * power(x, n - 1); // This is just the recursive // definition restated in } } // Java!

4. import java.io.*; class ArithmeticOperator { public static int num; public static int num1; public static void main(int num1, int num2){ num=num1; num1=num2; } public int Addition(){ return(num+num1); } public int Subtract(){ return(num-num1);

} public int Multiply(){ return(num*num1); } public int Divide(){ return(num/num1); } public static void main(String args[]){ try{ ArithmeticOperator arithmeticOperator= new ArithmeticOperator(); BufferedReader object= new BufferedReader(new InputStreamReader(System.in )); System.out.println("Enter the Number"); arithmeticOperator.num=Integer.parseInt(object.readLine()); arithmeticOperator.num1=Integer.parseInt(object.readLine()); int addition=arithmeticOperator.Addition(); int subtract=arithmeticOperator.Subtract(); int multiply=arithmeticOperator.Multiply(); int divide=arithmeticOperator.Divide(); System.out.println("values is num="+ arithmeticOperator.num); System.out.println("value is num1="+ arithmeticOperator.num1); System.out.println("Addtion is="+ arithmeticOperator.Addition()); System.out.println("Subtruct is="+ arithmeticOperator.Subtract()); System.out.println("Multiply is="+ arithmeticOperator.Multiply()); System.out.println("Divide is="+ arithmeticOperator.Divide()); } catch(Exception e){} } }

5. class Overload { double volume(float l, float w, float h) { return l * w * h; }

double volume(float l) { return l * l * l; }

double volume(float r, float h) { return 3.1416 * r * r * h; } } public class MethodOverloading { public static void main(String args[]) { Overload overload = new Overload(); double rectangleBox = overload.volume(5, 8, 9); System.out.println("Volume of rectangular box is " + rectangleBox); System.out.println(""); double cube = overload.volume(5);

System.out.println("Volume of cube is " + cube); System.out.println(""); double cylinder = overload.volume(6, 12); System.out.println("Volume of cylinder is " + cylinder); } }

6. class MatrixMultiply{ public static void main(String[] args) { int array[][] = {{5,6,7},{4,8,9}}; int array1[][] = {{6,4},{5,7},{1,1}}; int array2[][] = new int[3][3]; int x= array.length; System.out.println("Matrix 1 : "); for(int i = 0; i < x; i++) { for(int j = 0; j <= x; j++) { System.out.print(" "+ array[i][j]); } System.out.println(); } int y= array1.length; System.out.println("Matrix 2 : "); for(int i = 0; i < y; i++) { for(int j = 0; j < y-1; j++) { System.out.print(" "+array1[i][j]); }

System.out.println(); } for(int i = 0; i < x; i++) { for(int j = 0; j < y-1; j++) { for(int k = 0; k < y; k++){ array2[i][j] += array[i][k]*array1[k][j]; } } } System.out.println("Multiply of both matrix : "); for(int i = 0; i < x; i++) { for(int j = 0; j < y-1; j++) { System.out.print(" "+array2[i][j]); } System.out.println(); } } }

7.

import java.io.*; import java.util.*; class CountCharacters { public static void main(String[] args) throws Exception{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please enter string "); System.out.println();

String str=br.readLine(); String st=str.replaceAll(" ", ""); char[]third =st.toCharArray(); for(int counter =0;counter<third.length;counter++){ char ch= third[counter]; int count=0; for ( int i=0; i<third.length; i++){ if (ch==third[i]) count++; } boolean flag=false; for(int j=counter-1;j>=0;j--){ if(ch==third[j]) flag=true; } if(!flag){ System.out.println("Character :"+ch+" occurs "+count+" times "); } } } } 8. import java.util.*; import java.io.*;

class MenuDriven { publicstaticvoid main(String args[])

{ Vector itemList = new Vector(); String str,item; int i,j,len,choice,pos;

len=args.length; for(i=0;i<len;i++) itemList.addElement(args[i]);

while(true) { System.out.println("\n\nChoose your choice ..."); System.out.println("1) Delete Item"); System.out.println("2) Add Item at Specified Location "); System.out.println("3) Add Item at the End of the list"); System.out.println("4) Print Vector List "); System.out.println("5) Exit"); System.out.print("Enter your choice : "); System.out.flush(); try{ BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));

str=obj.readLine(); choice=Integer.parseInt(str); switch(choice) { case 1 : System.out.print("Enter Item you want to delete : "); str=obj.readLine(); itemList.removeElement(str); //string is not needed to convert object type as it //is already object of class String break; case 2 : System.out.print("Enter Item to be Insert : "); System.out.flush(); item=obj.readLine(); System.out.print("Enter Position to insert item : "); str=obj.readLine(); pos=Integer.parseInt(str); itemList.insertElementAt(item,pos-1); break; case 3 : System.out.print("Enter Item to be Insert : "); System.out.flush(); item=obj.readLine();

itemList.addElement(item); break; case 4 : len=itemList.size(); System.out.println("\nItem Display "); for(i=0;i<len;i++) { System.out.println((i+1)+") "+itemList.elementAt(i)); } break; case 5 : software....."); System.out.println("\n\nThank You for using this

System.exit(1); break; default : Again\n"); } } catch(Exception e) {} } } } System.out.println("\nEntered Choice is Invalid\nTry

9.

También podría gustarte