Home / Java Programming / Flow Control :: General Questions

Java Programming :: Flow Control

  1.  

    public void foo( boolean a, boolean b) 
    {     
     if( a )     
     {       
         System.out.println("A"); /* Line 5 */    
     }    
     else if(a && b) /* Line 7 */    
     {      
         System.out.println( "A && B");  
     }    
     else /* Line 11 */  
     {       
       if ( !b )        
       {           
            System.out.println( "notB") ;     
        }          
        else         
        {             
            System.out.println( "ELSE" ) ;      
        }      
       } 
     } 
    

  2. A.

    If a is true and b is true then the output is "A && B"

    B.

    If a is true and b is false then the output is "notB"

    C.

    If a is false and b is true then the output is "ELSE"

    D.

    If a is false and b is false then the output is "ELSE"

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. switch(x)

    {

      default:

         System.out.println("Hello");

     }

    Which two are acceptable types for x?

    1. byte
    2. long
    3. char
    4. float
    5. Short
    6. Long

  4. A.

    1 and 3

    B.

    2 and 4

    C.

    3 and 5

    D.

    4 and 6

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. public void test(int x)  {      int odd = 1;      if(odd) /* Line 4 */     {         System.out.println("odd");      }      else      {         System.out.println("even");      }  } 
    Which statement is true?

  6. A.
    Compilation fails.
    B.
    "odd" will always be output.
    C.
    "even" will always be output.
    D.
    "odd" will be output for odd values of x, and "even" for even values.

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. public class While  {     public void loop()      {         int x= 0;         while ( 1 ) /* Line 6 */         {             System.out.print("x plus one is " + (x + 1)); /* Line 8 */         }     } } 
    Which statement is true?

  8. A.
    There is a syntax error on line 1.
    B.
    There are syntax errors on lines 1 and 6.
    C.
    There are syntax errors on lines 1, 6, and 8.
    D.
    There is a syntax error on line 6.

    View Answer

    Workspace

    Discuss Discuss in Forum