You are on page 1of 5

30608205014 PROGRAM: import java.io.*; import java.util.

*; public class complexnumber { private int a; private int b; public complexnumber() { } public complexnumber(int a,int b) { this.a=a; this.b=b; } public String getcomplexvalue() { if(this.b<0) { return a+" "+b+"i"; } else { return a+"+"+b+"i"; }} public static String addition(complexnumber num1,complexnumber num2) { int a1=num1.a+num2.a; int b1=num1.b+num2.b; if(b1<0) { return a1+" "+b1+"i"; } else { return a1+"+"+b1+"i"; } } public static String subtractioncomplex(complexnumber num1,complexnumber num2) { int a1=num1.a-num2.a; int b1=num1.b-num2.b; if(b1<0)

{ return a1+" "+b1+"i"; } else { return a1+"+"+b1+"i"; }} public static String multiplication(complexnumber num1,complexnumber num2) { int a1=num1.a*num2.a; int b1=num1.b*num2.b; int vi1=num1.a*num2.b; int vi2=num2.a*num1.b; int vi; vi=vi1+vi2; if(vi<0) { return a1-b1+" "+vi+"i"; } else { return a1-b1+"+"+vi+"i"; } } public static void main(String args[]) { complexnumber com1=new complexnumber(-2,-3); complexnumber com2=new complexnumber(-4,-5); System.out.println(com1.getcomplexvalue()); System.out.println(com2.getcomplexvalue()); System.out.println("Addition of both complexnumbers:"+ complexnumber.addition(com1,com2)); System.out.println("Subtraction of both complexnumbers:"+ complexnumber.subtractioncomplex(com1,com2)); System.out.println("Multiplication of both complexnumbers"+ complexnumber.multiplication(com1,com2)); } }

OUTPUT: -2 -3i -4 -5i Addition of both complexnumbers:-6 -8i Subtraction of both complex numbers:2+2i Multiplication of both complex numbers -7+22i

30608205014 PROGRAM: import java.io.*; import java.util.*; public class queue { LinkedList <Integer> list; int num; public static void main(String args[]) { queue q=new queue(); } public queue() { try { list=new LinkedList<Integer>(); DataInputStream d=new DataInputStream(System.in); System.out.println("Enter the number of element"); if((num=Integer.parseInt(d.readLine()))==0) { System.out.println("YOU entered zero\null"); System.exit(0); } else { System.out.println("Enter the element"); for(int i=0;i<num;i++) { int n=Integer.parseInt(d.readLine()); list.add(n); }} while(!list.isEmpty()) { System.out.println("Deleted Element:"+list.removeFirst()); System.out.println(list); } } catch(IOException e) { System.out.println(e.getMessage()+"is not a legal entry"); System.exit(0); }}}

OUTPUT: Enter the number of element 5 Enter the element 1 2 3 4 5 Deleted Element:1 [2, 3, 4, 5] Deleted Element:2 [3, 4, 5] Deleted Element:3 [4, 5] Deleted Element:4 [5] Deleted Element:5 []