What is the output from the following program class Test pub

What is the output from the following program? class Test {public static void main (String[] args) {int x = 12, y = 3; int counter = 0; while (counter

Solution

public class Test {

       public static void main(String[] args){

           int x = 12, y =3;

           int counter = 0;

           while(counter < 5){ // we are executing 5 TIMES this while loop

               try{

                   if( y<0)

                       return;

                   x = x/y; // dividing x by y

                   System.out.println(\"x: \"+x+\" y: \"+y); // always get printed on control

                  

               }catch(Exception e){ // if there is any exception occurs in try block then this

                                       // catch block will handle it

                   System.out.println(\"can\'t divide by 0\");

               }finally{ // this block executes always

                   ++counter; // counter will increase by one in each iteration

                   System.out.println(\"finally: \"+counter); // always get printed on console

               }

               --y; // decreasing y

               ++x; // increasing x

               System.out.println(\"After exception\"); // this will always printed on console

           }

       }

}

/*

Output:

x: 4 y: 3

finally: 1

After exception

x: 2 y: 2

finally: 2

After exception

x: 3 y: 1

finally: 3

After exception

can\'t divide by 0

finally: 4

After exception

finally: 5

*/

5)
   public int getFrequencyOf(T anEntry){

       int count = 0;

       T temp = firstNode; // storing temp with first node of bag

       while(temp != null){

           // if current node euals to anEntry
           if(temp.compareTo(anEntry) == 0)
               count++;

           temp = temp.getNext();
       }

       return count;

   }

 What is the output from the following program? class Test {public static void main (String[] args) {int x = 12, y = 3; int counter = 0; while (counter Solution
 What is the output from the following program? class Test {public static void main (String[] args) {int x = 12, y = 3; int counter = 0; while (counter Solution

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site