Evaluating Methods: Lab 7b


Identify the output produced by the segments of code below or indicate if an error occurs.
  1.           public static void main(String[] args ){
                int x = 2, y = 3, z = 0;
                z = p(x,y);
                System.out.print( "x = " +  x +  "y = " +  y + "z = " +  z);
              }
    
              public static int p (int a, int b ){
                int x = 21;
                a = 31;
                b = 41
                return b - a;
              }
            
  2.           public static void main(String[] args ){
                int x = 2, y = 3;
                x = p(x,y);
                x = p(x,y);
                x = p(x,y);
                System.out.print( "x = " +  x +  "y = " +  y);
              }
              
              public static int p (int y, int x){
                return 2*x + y;
              }
            
  3.           public static void main(String[] args ){
                int x = 2, y = 3, z = 0;
                x = p(x,y);
                System.out.print( "x = " +  x +  "y = " +  y + "z = " +  z);
                x = p(x,y);
                System.out.print( "x = " +  x +  "y = " +  y + "z = " +  z);
              }
    
              public static int p (int x, int z ){
                int y = z;
                return x - z;
              }
            
  4.           public static void main(String[] args ){
                int x = 2, y = 3, z = 0;
                display (x, z);
                System.out.print("INSIDE MAIN");
                System.out.print( "x = " +  x +  "y = " +  y + "z = " +  z);
              }
    
              public static void display (int x, int y){
                int z = x;
                System.out.print("INSIDE DISPLAY");
                System.out.print( "x = " +  x +  "y = " +  y + "z = " +  z);
              }
            
    Why is there no return statement in the Display method? Why is the call to display() not part of an assignment statement?
  5.           public static void main(String[] args ){
                int x = 2, y = 3, z = 0;
                display (x, y, z);
              }
    
              public static void display (int a, int b, int c ){
                System.out.println( "a = " +  a +  "b = " +  b + "c = " +  c);
              }
            
  6.           public static void main(String[] args ){
                int x = 2, y = 3, z = 0;
                display (x, y, z);
                System.out.println("INSIDE MAIN");
                System.out.println( "x = " +  x +  "y = " +  y + "z = " +  z);
              }
    
              public static void display (int y, int z, int x ){
                System.out.println("INSIDE DISPLAY");
                System.out.println( "x = " +  x +  "y = " +  y + "z = " +  z);
              }