NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 1 | P a g e DESIGN AND ANALYSIS OF ALGORITHM LABORATORY [As per Choice Based Credit System (CBCS) scheme] (Effec tive from the academic year 2018 - 2019 ) SEMESTER – IV Subject Code 18 CSL47 IA Marks 40 Nu mber of Lecture Hours/Week 01 T + 02 P Exam Marks 60 Total Number of Lecture Hours 40 Exam Hours 03 CREDITS – 02 Course objectives: This course will enable students to • Design and implement various algorithms in JAVA • Employ various design strategies for problem solving. • Measure and compare the performance of different algorithms. Description Design, develop, and implement the specified algorithms for the following problems using Java language under LINUX /Windows environment.Netbeans/Eclipse IDE tool can be u sed for development and demonstration. Experiments 1 A Create a Java class called Student with the following details as variables within it. (i) USN (ii) Name (iii) Branch (iv) Phone Write a Java program to create nStudent objects and print the USN, Name, Branch, and Phone of these objects with suitable headings. 1 B Write a Java program to implement the Stack using arrays. Write Push ( ), Pop ( ), and Display ( ) methods to demonstrate its working. 2 A Design a superclass called Staff with details as StaffId, Name, Phone, Salary. Extend this class by writing three subclasses namely Teaching (domain, publications), Technical (skills), and Contract (period). Write a Java program to read and display at lea st 3 staff objects of all three categories. 2 B Write a Java class called Customer to store their name and date_of_birth. The date_of_birth format should be dd/mm/yyyy. Write methods to read customer data as <name, dd/mm/yyyy> and display as <name, dd, mm, yyyy> using StringTokenizer class considering the delimiter character as “/”. 3 A Write a Java program to read two integers a and b . Compute a / b and print, when b is not zero. Raise an exception when b is equal to zero. 3 B Write a Java program that implements a multi - thread application that has three threads. First thread generates a random integer for every 1 second; second thread computes the square of the number and prints; third thread will print the value of cube of the number. 4 Sort a given set of n integer elements using Quick Sort method and compute its time complexity. Run the program for varied values of n > 5000 and record the time taken to sort. Plot a graph of the time taken versus n on graph sheet. The elements can be read from a file or can be generated using the random number generator. Demonstrate using Java how the divide and - conquer method works along with its time complexity analysis: worst case, average case and best case. NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 2 | P a g e 5 Sort a given set of n integer elements u sing Merge Sort method and compute its time complexity. Run the program for varied values of n > 5000, and record the time taken to sort. Plot a graph of the time taken versus n on graph sheet. The elements can be read from a file or can be generated using the random number generator. Demonstrate using Java how the divide and - conquer method works along with its time complexity analysis: worst case, average case and best case. 6 Implement in Java, the 0/1 Knapsack problem using (a) Dy namic Programming method (b) Greedy method. 7 From a given vertex in a weighted connected graph, find shortest paths to other vertices using Dijkstra's algorithm . Write the program in Java. 8 Find Minimum Cost Spanning Tree of a given connected undirected graph using Kruskal'salgorithm. Use Union - Find algorithms in your program. 9 Find Minimum Cost Spanning Tree of a given connected undirected graph using Prim's algorithm 10 Write Java programs to (a) Implement All - Pairs Shortest Paths problem using Floyd's algorithm (b) Implement Travelling Sales Person problem using Dynamic programming. 11 Design and implement in Java to find a subset of a given set S = {Sl, S2,.....,Sn} of n positive integers whose SUM is equal to a given pos itive integer d . For example, if S = { 1, 2, 5, 6, 8} and d = 9, there are two solutions {1 , 2, 6} and {1 , 8 }. Display a suitable message, if the given problem instance doesn't have a solution. 12 Design and implement in Java to find all Hamiltonian Cycles in a connected undirected Graph G of n vertices using backtracking principle. Course Outcomes: The students should be able to: • Design algorithms using appropriate design techniques (brute - forc e, greedy, dynamic programming, etc.) • Implement a variety of algorithms such assorting, graph related, combinatorial, etc., in a high level language. • Analyze and compare the performance of algorithms using language features. • Apply and implement learn ed algorithm design techniques and data structures to solve real world problems. Graduate Attributes • Engineering Knowledge • Problem Analysis • Modern Tool Usage • Conduct Investigations of Complex Problems • Design/Development of Solutions Conduction of Practical Examination: All laboratory experiments (Twelve problems) are to be included for practical examination. Students are allowed to pick one experiment from the lot. To generate the data set use random number generator function. Strict ly follow the instructions as printed on the cover page of answer script for breakup of marks Marks distribution: Procedure + Conduction + Viva: 20 + 50 + 10 (80). Change of experiment is allowed only once and marks allotted to the procedure NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 3 | P a g e INTRODUCTION Analysis of algorithms Analysis is one of the important step in problem solving. Here we estimate time and space for a given problem. Once we have these estimations, select an algorithm which is more efficient in terms of time and space. Time Efficiency: Indicates how fast th e algorithm runs. Space Efficiency: Indicates how much extra memory is required for the algorithm. The most important characteristics of any algorithm are it’s simplicity and generality. Simplicity: Simple algorithms are easy to understand, debug an d easy to program. Generality: It should be a generic solution to the given problem. Design an algorithm After the problem is clearly stated and the type of algorithm and data structure are selected, the solution to solve the problem should be specified. One or more algorithms may be correct to solve a given problem. But effectiveness may be different from solution to solution. Algorithm An algorithm is a technique to solve a problem systematically. It takes a set of input and produces a desired output . Now algorithm can be defined as an unambiguous an ordered sequence of steps that are carried to get a solution to a problem. Pictorial representation of an algorithm is as shown below : The Software Requirements: Opera t ing System : Windows 7 Supportin g Packages : Eclipse IDE tool NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 4 | P a g e 1 A Create a Java class called Student with the following details as variables within it. (i) USN (ii) Name (iii) Branch (iv) Phone Write a Java program to create nStudent objects and print the USN, Name, Branch, and Phone of these objects with suitable headings. Aim: The aim of this program is to create a class and make objects of that class to print the details of a student. Implementation: • Create a class named “student”. • Declare variables within it containing the details like name, USN, Branch, Phone no • Create a constructor to initialize these variables. • Create a function that prints these details like usn, name, branch and phone no. • Create multiple objects of “student” class that calls the fun ction to print the details. Algorithm: //Input: Values for USN, name, branch and phone no //Output: Displaying the details of n student objects //Steps: 1) class “student” is created 2) Declare variables USN, Name, Branch, and Phone no. 3) a constructor of Student class is create d to initialize these variable. 4 ) multiple objects of “student” class is created and print the details contained in student class. Program : package soumya; import java.util.Scanner; public class Student { String USN;//USN String Name;//Name String Branch;//Branch Long Phone;//Phone number public Student(String U,String N,String B,Long P) { this.USN=U; this.Name=N; this.Branch=B; this.Phone=P; } public static void main(String args[]) { Scanner input=new Scanner(System.in); System.out.println("enter number of Students:"); NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 5 | P a g e int n=input.nextInt(); Student[] s=new Student[n];//array of objects definition System.out.println("enter s tudent details:"); for(int i=0;i<n;i++) { System.out.println((i+1)+"Student details:"); System.out.println("USN"); String USN=input.next(); System.out.println("Name"); String Name=input.next(); System.out.println("Bran ch"); String Branch=input.next(); System.out.println("Phone"); Long Phone=input.nextLong(); s[i]=new Student(USN,Name,Branch,Phone);//instanting each object } System.out.println("Student Details:"); System.out.println("USN"+" \ t"+"Name"+" \ t"+"Branch"+" \ t"+"Phone"); System.out.println(" ----------------------------- "); for(int i=0;i<n;i++) { System.out.println(s[i].USN+" \ t"+s[i].Name+" \ t"+s[i].Branch+" \ t"+s[i].Phone); } } } output: enter number of Students: 2 enter student details: 1Student details: USN 4cs34 Name soumya Branch cse Phone 90876543 2Student details: USN 4cs56 Name shruthi Branch NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 6 | P a g e cse Phone 4532167895 Student Details: USN Name Branch Phone ----------------------------- 4cs34 soumya cse 90876543 4cs56 shruthi cse 4532167895 NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 7 | P a g e 1B Write a Java program to implement the Stack using arrays. Write Push(), Pop(), and Display() methods to demonstrate its working. Aim: The aim of this program is to create stack using arrays and perform all the stack related functions like pushing elements, popping elements and displaying the contents of stack. Stack is abstract data type which demonstrates Last in first out (LIFO) behavior. We will impl ement same behavior using Array. Implementation: • A class is created that contains the defined array as well as all the variables defined • Constructor initialize those variables and array • Function are created for pushing he elements into stack • Function are created for popping the elements from stack • Function are created for displaying the contents of stack Algorithm: // Input : Elements to be pushed or popped from the Stack // Output : pushed elements, popped elements, contents of stack Steps: 1) A class created and variables are defined like size, array[], top 2) A customized constructor of same class is used for initializing size, top variables and the array[] 3) A function created for pushing the elements into stack : push(int pushedEl emnet) { If(stack is not full) { Top++; Array[top]=pushedElement; } Else { Stack is full } } 4) A function created for popping the elements from stack : Pop() { If(stack is not empty) { A=top; Top -- ; } Else { Stack is empty } } 5) A function is created for displaying the elements in the stack: printElemnts() { If(top>=0) { For(i=0;i<=top;i++) { Print all elements of array } } NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 8 | P a g e Program: package soumya; import java.util.Scanner; public class lab1b { int top; int size; int[] stk; public lab2b() { size=3; top= - 1; stk=new int[10]; } @SuppressWarnings("resource") void push() { if(top>=size - 1) { System.out.println("stack overflow"); return; } top=top+1; Scanner input=new Scanner(System.in); System.out.println("ent er an element to push"); stk[top]=input.nextInt(); } void pop() { if(top== - 1) { System.out.println("stack underflow"); return; } int del_item=stk[top]; top=top - 1; System.out.println("popped item="+del_item); } void display() { if(top== - 1) { System.out.println("stack underflow"); return; } for(int i=top;i>=0;i -- ) { System.out.println("stack["+i+"]"+stk[i]); } } @SuppressWarnings("resource") public static void main(String args[]) { lab2b obj=new lab2b(); Scanner input=new Scanner(System.in); for(;;) NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 9 | P a g e { System.out.println(" --- Stack Operation --- "); System.out.println("1:push \ n 2:pop \ n 3:display \ n 4:exit"); System.out.println("enter your choice:"); int choice=input.nextInt(); swit ch(choice) { case 1:obj.push(); break; case 2:obj.pop(); break; case 3:obj.display(); break; default:System.out.println("invalid choice"); System.exit(1); } } } } Output: --- Stack Operation --- 1:push 2:pop 3:display 4:exit enter your choice: 1 enter an element to push 3 --- Stack Operation --- 1:push 2:pop 3:display 4:exit enter your choice: 1 enter an element to push 6 --- Stack Operation --- 1:push 2:pop 3:display 4:exit enter your choice: 3 stack[1]6 stack[0]3 --- Stack Operation --- 1:push 2:pop 3:display 4:exit enter your choice: 2 popped item=6 NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 10 | P a g e --- Stack Operation --- 1:push 2:pop 3:display 4:exit enter your choice: 2 popped item=3 --- Stack Operation --- 1:push 2:pop 3:display 4:exit enter your choice: 1 enter an element to push 3 --- Stack Operation --- 1:push 2:pop 3:display 4:exit enter your choice: 2 popped item=3 --- Stack Operation --- 1:push 2:pop 3:display 4:exit enter your choice: 3 stack underflow --- Stack Operation --- 1:push 2:pop 3:display 4:exit enter your choice: 2 stack underflow --- Stack Operation --- 1:push 2:pop 3:display 4:exit enter your choice: 3 stack underflow --- Stack Operation --- 1:push 2:pop 3:display 4:exit NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 11 | P a g e 2 A Design a superclass called Staff with details as StaffId, Name, Phone, Salary. Extend this class by writing three subclasses namely Teaching (domain, publications), Technical (skills), and Contract (period). Write a Java program to read and display at least 3 staff objects of all three categories. Aim : Understanding the concepts of inheritance and accessing the members of super class and sub class Implementation: • A class created named “staff” • Variab les are declared in th e class like StaffId, Nam e, PhoneNo, Salary. • Constructor is used to initialize the values of these variables. • Three more classes named “Teaching”, “Technical”, and “Contract” are created that inherits the features of super class “staff” • Function is created to display 3 staff objects of all three classes. Algorithm: //Input: StaffId, Name, Phone and Salary //Outpu t: displaying the three staff objects of each class. Steps: 1) A class created named “staff”. 2) Variables are declared in the class like StaffId, Name , PhoneNo, Salary. 3) Constructor is used to initialize the values of these variables. 4) Function is created to read values from console of the variables: readValues() { Scanner s1 new Scanner(System.in); // Scanner class is defined in library in “java.util.Scanner” package. We need to import //this package in our program for successful compil ation. System.out.println(“enter staff id”); StafId= (s1.next()); System.out.println(“enter name”); name= (s1.next()); System.out.println(“enter phone”); phone= (s1.next()); System.out.println(“enter salary”); salary= (s1.nextInt()); } 5) Subclass “teachin g” is created that inherits superclass “staff”. 6) Two functions are defined inside “teaching” class. They are “domain” and “publications”. These f unctions print the domain of particular staff and no. of publications by him respectively. 7) A class is created “technical” that inherits super class “staff”. 8) One function is defined under “technical” class named “skills”. This functions displays the skills of particular staff. 9) A class is created named “contract” that inherits the super class “staff” 1 0) One function is defined under “contract” class named “period”. This function displayed the contract period of the particular staff. 11) From the main method, objects are made of each subclass and functions are called. Public static void main(String args []) { Teaching t1= new Teaching(); t1.readValue(); t1.domain(); t1.publications(): Technical t2=new Technical(); t2.readValue(); t2.skills(); Contract c1=new Contract(); c1.readValue(); c1.period(); } NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 12 | P a g e Program: package newstaffproj; import java.util.Scanner; class Staff { String StaffID, Name, Phone, Salary; Scanner input = new Scanner(System.in); void read() { System.out.println("Enter StaffID"); StaffID = input.nextLine(); System.out.println("Enter Name"); Name = input.nextLine(); System.out.println("Enter Phone"); Phone = input.nextLine(); System.out.println("Enter Salary"); Salary = input.nextLine(); } void display() { System.out.prin tf(" \ n% - 15s", "STAFFID: "); System.out.printf("% - 15s \ n", StaffID); System.out.printf("% - 15s", "NAME: "); System.out.printf("% - 15s \ n", Name); System.out.printf("% - 15s", "PHONE:"); System.out.printf("% - 15s \ n", Phone); System.out.printf(" % - 15s", "SALARY:"); System.out.printf("% - 15s \ n", Salary); } }//end of Staff superclass class Teaching extends Staff { String Domain, Publication; void read_Teaching() { super.read(); // call super class read method System.out.println("Enter Domain:"); Domain = input.nextLine(); System.out.println("Enter Publication:"); Publication = input.nextLine(); } void display() { super.display(); // call super class display() method System.out .printf("% - 15s", "DOMAIN:"); NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 13 | P a g e System.out.printf("% - 15s \ n", Domain); System.out.printf("% - 15s", "PUBLICATION:"); System.out.printf("% - 15s \ n", Publication); } }//end of Teaching subclass class Technical extends Staff { String Skills; void read_Technical() { super.read(); // call super class read method System.out.println("Enter Skills:"); Skills = input.nextLine(); } void display() { super.display(); // call super class display( ) method System.out.printf("% - 15s", "SKILLS:"); System.out.printf("% - 15s \ n", Skills); } }//end of Technical class class Contract extends Staff { String Period; void read_Contract() { super.read(); // call super class read method System.out.println("Enter Period"); Period = input.nextLine(); } void display() { super.display(); // call super class display() method System.out.printf("% - 15s", "PERIOD:"); System.out.printf("% - 15s \ n", Period); } }//end of Contract subclass class DemoStaff { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter number of staff details to be created"); int n = input.ne xtInt(); NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 14 | P a g e Teaching steach[] = new Teaching[n]; Technical stech[] = new Technical[n]; Contract scon[] = new Contract[n]; // Read Staff information under 3 categories for (int i = 0; i < n; i++) { System.out.println("Enter Teaching staff information"); steach[i] = new Teaching(); steach[i].read_Teaching(); } for (int i = 0; i < n; i++) { System.out.println("Enter Tech nical staff information"); stech[i] = new Technical(); stech[i].read_Technical(); } for (int i = 0; i < n; i++) { System.out.println("Enter Contract staff information"); scon[i] = new Contract(); sco n[i].read_Contract(); } // Display Staff Information System.out.println(" \ n STAFF DETAILS: \ n"); System.out.println(" ----- TEACHING STAFF DETAILS ----- "); for (int i = 0; i < n; i++) { steach[i].display(); } System.out.println(" \ n ----- TECHNICAL STAFF DETAILS ----- "); for (int i = 0; i < n; i++) { stech[i].display(); } System.out.println(" \ n ----- CONTRACT S TAFF DETAILS ----- "); for (int i = 0; i < n; i++) { scon[i].display(); } input.close(); }//end of main method }//end of class DemoStaff output: Enter number of staff details to be created 2 Enter Teaching staff information NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 15 | P a g e Enter StaffID cs34 Enter Name smriti Enter Phone 9023456712 Enter Salary 20000 Enter Domain: cs Enter Publication: tcs Enter Teaching staff information Enter StaffID cs45 Enter Name shruti Enter Phone 5642134567 Enter Salary 25000 Enter Domain: cs Enter Publication: rhi Enter Technical staff information Enter StaffID 2 Enter Name deepu Enter Phone 5432134567 Enter Salary 4500 Enter Skills: c Enter Technical staff information Enter StaffID 2 Enter Name deepak Enter Phone 4532167865 Enter Salary 5600 Enter Skills: c++ Enter Contract staff information Enter StaffID 35 Enter Name gowri Enter Phone 4532167890 Enter Salary 4500 NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 16 | P a g e Enter Period 3 Enter Contract staff information Enter StaffID 26 Enter Name reema Enter Phone 3214567892 Enter Salary 43200 Enter Period 4 STAFF DETAILS: ----- TEACHING STAFF DETAILS ----- STAFFID: cs34 NAME: smriti PHONE: 9023456712 SALARY: 20000 DOMAIN: cs PUBLICATION: tcs STAFFID: cs45 NAME: shruti PHONE: 5642134567 SALARY: 25000 DOMAIN: cs PUBLICATION: rhi ----- TECHNICAL STAFF DETAILS ----- STAFFID: 2 NAME: deepu PHONE: 5432134567 SALARY: 4500 SKILLS: c STAFFID: 2 NAME: deepak PHONE: 4532167865 SALARY: 5600 SKILLS: c++ ----- CONTRACT STAFF DETAILS ----- STAFFID: 35 NAME: gowri PHONE: 4532167890 SALARY: 4500 PERIOD: 3 STAFFID: 26 NAME: reema PHONE: 3214567892 SALARY: 43200 PERIOD: 4 NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 17 | P a g e 2B Write a Java class called Customer to store their name and date_of_birth. The date_of_birth format should be dd/mm/yyyy. Write methods to read customer data as <name, dd/mm/yyyy> and display as <name, dd, mm, yyyy> using StringTokenizer class considering t he delimiter character as “/”. Aim: Understanding the concepts of StringTokenizer class and separating the strings on the basis of different delimiters. Implementation: • Create a class named “customer”. • Store the values of name and date of birth in the variables named as “name” and “date_of_birth” • Create an object of StringTokennizer class and call the methods to separate the strings separated by “/” delimi ter. • Display the name and date of birth in the format specified as the output. Algorithm: //input: name and dtae_of_birh in dd/mm/yyy format //Output: name and date of birth displayed in <name, dd, mm, yyy> format Steps: 1) A class named “customer” is created. 2) Variables are defined as name and date_of_birth 3) Values are read from the user of name a nd date of birth in dd/mm/yyy format as strings. Scanner sc = new Scanner(System. in ); System. out .println("enter name"); String name=sc.next(); System. out .println("enter date of birth in dd/mm/yyy format"); String date = sc.next(); 4) A object is created of StringTokenizer class and is used for calling the method of this class. 5) The method “hasmoreelements” and “nextElement” is used for extracting the strings separated by “/” delimeter StringTokenizer strToken = new StringTokenizer(date, "/"); 6) The output is displayed then in the form of <name, dd, mm, yyy> Program: package soumya; import java.util.Scanner; import java.util.StringTokenizer; public class lab2b { String name; String date_of_birth; void display(String name,String date) { StringTokenizer to=new StringTokenizer(date,"/"); String temp=to.nextToken(); int dd= Integer.parseInt(temp); temp=to.nextToken(); int mm=Integer.parseInt(temp); temp=to.nextToken(); int yyyy=Integer.parseInt(temp); System.out.println(name+","+dd+","+mm+","+yyyy); } void readCust() { Scanner sc=new Scanner(System.in); System.out.println("enter name"); String name=sc.next(); System.out.println("enter date of birth"); NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 18 | P a g e String date=sc.next(); display(name,date); } public static void main(String[] args) { // TODO Auto - generated method stub lab2 obj=new lab2(); obj.readCust(); } } output: enter name soumya enter date of birth 18/11/1985 soumya,18,11,198 5 NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 19 | P a g e 3 A Write a Java program to read two integers a and b . Compute a / b and print, when b is not zero. Raise an exception when b is equal to zero. AIM: Understanding the concepts of exception handling in java Implementation: • A class is created containing the main method • Inside the main method the calculation is done of division using two operands • Try and Catch block is implemented for handling the arithmetic exception raised when division is done by zero • Else the final output is printed Algorith m: // Input: values of two operand i.e a and b // Output: a) answer displayed when b != 0 b) Arithmetic exception raised and error message displayed when b = 0. Steps : 1) A class is created containing the main method 2) Two variables are declared i.e. a and b 3) Input is obtained from console Scanner sc = new Scanner(System. in ); a = sc.nextInt(); b = sc.nextInt(); 4) The code to calculate division is kept under try block try{ System. out .println( a / b ); } 5) The arethemetic exception raised when b=0 i s handled in catck block that follows try block catch(ArithmeticException e){ e.printStackTrace(); } Program: import java.util.Scanner; public class lab3a { public static void main(String[] args) { // TODO Auto - generated method stub Scanner input=new Scanner(System.in); System.out.println("Enter TWO numbers :"); double number1=input.nextDouble(); double number2=input.nextDouble(); Double quotient=(number1 / number2); System .out.println("The quotient is " + quotient); if(number2!=0) { System .out.println("the value of number1 " +number1); System.out.println("the value of number2 " +number2); } else throw new ArithmeticException("Not valid"); } } NIEIT, Mysuru Design and Analysis of Algorithm Lab 18 CSL47 Department of Computer Science & Engg. 20 | P a g e OUTPUT: Enter TWO numbers : 5 3 the value of number1 5.0 the value of number2 3.0 The quotient is 1.6666666666666667 Enter TWO numbers : 4 0 Exception in thread "main" java.lang.ArithmeticException: Not valid at newstaffproj.lab3a.main(lab3a.java:23)