2.

   public static void main(String [] args)

   {

           int a =   /// initalize in question

           int b =   /// initalize in question

           int c =   /// initalize in question

  

 

           if(a < b && b> c)

                System.out.println(“print statement one”);

          else if(b<c || a < b)

                System.out.println(“print statement two”);

         else if(b< c && b==3)

                System.out.println(“Print statement three);

          else

                System.out.println(“print statement four);

}

 

 

 Give examples of initialization that would make the print statemtents above print to the screen.

A.          “print statement one”

 

 

B.          “print statement two”

 

 

C.           “print statement three”

 

 

 

D.         “print statement four”

 

 

 

3.

The following code is calling a method called subfun. You need to write the method subfun so the program prints the values the comments say are going to be printed. The method should be very short; you get more points for the minimum amount of executable statements in the method subfun. 

 

     Public static void main(String [] args)

    {

         int answer;

        

        answer = subfun(1, 0, 3);

        System.out.println(answer);  //this will print 3

  

       answer = subfun(3, 2, 3);

        System.out.println(answer);  //this will print 9

 

        answer = subfun(2, 2, 8);

        System.out.println(answer);  //this will print 12

     }

 

 

 

 

 

 

 

 

 

 

 

 

4. Given the following menu

          Press 1 to add 2 to the answer

          Press 2 to subtract 2 from the answer

          Press 3 to exit

          Press anything else to reset the answer to 0

 

Write the code that would implement the choices. Assume the menu is in the method called menu and the menu method returns the user input. This is the code you have so far:

 

   Public void static main(String [] args)

  {

          int choice, answer = 0;

 

       do{

             choice =  menu();

             

 

 

 

 

 

 

 

 

      }while(               )

 

  }

 


5. Given the following code:

    

 

     public static void main(String [] args)

   {

 

            int [] a = {1, 2, 3, 4, 5};

           

             for(int I=0; I<a.length; I++)

                  a[I] = I * a[I];

                

             for(int I = 0; I<a.length; I++)

                    System.out.println(a[I]);  //Question A

 

             a[0] = subfun(i);

 

             for(int I = 0; I<a.length; I++)

                    System.out.println(a[I]);  //Question B

 

             a[0] =  subfun(a[3]);

 

             for(int I = 0; I<a.length; I++)

                    System.out.println(a[I]);   //Question C

}

 

public static int subfun(b [] int)

 {

         for(int I = 0; I<b.length; I++)

                b[I] = 5;

                return 1;

}

public static int subfun(int b)

{

        return 100;

     }

 

Give the output at all the print statements, remember each print statement runs more than once.

 

A. //Question A

 

 

 

 

 

 

B.  //Question B

 

 

 

 

 

 

C.  //Question C