up

Mathematical Expressions

Modify the given program so that it will produce the following output. The only changes you are allowed to do is to replace 0 values with other values, in the assignments to the variables ‘i’, ‘j’, ‘k’, ‘a’, and ‘b’. Moreover, none of these variables may be assigned the 0 value.

1.  i / j + j % k = 
                                4 
2.  (double) i / j +  (double) j % k = 
                                4.333333333333333 
3.  (i>j) && !(j>k) = 
                                true 
4.  (i<j) || (j == k) = 
                                true 
5.  (i<j) && (j < k) && (k-2 == i) = 
                                true 
6.  ((i<j) || (j < k)) && ((i>j) || (j > k)) = 
                                true 
7.  (a-b) * (a+b) = 
                                16.0 
8.  Math.sqrt( a*a + b*b ) = 
                                5.0 
9.  Math.pow( i, j ) + Math.pow( j, i ) = 
                                17.0 
10.  if( i == 3 ) { bans = true; } else { bans = false; } = 
                                true 
11.  if( (i > 30) && (i < 32) ) { bans = true; }  = 
                                true 
Suggestion: First modify the given program so that it will compile and run without errors, disregarding the outcome of the output.
rec9.java
 class rec9 {
   public static void main ( String [] args ){
     int i, j, k, n=0, ians;
     double a, b, c, dans;
     boolean bans;
 
     i = 0;   j = 0;    k = 0;
     ians = i / j + j % k;
     System.out.println(
        ++n + ".  i / j + j % k  \n\t\t\t\t"
        +  ians );
 
     i = 0;   j = 0;    k = 0;
     dans = (double) i / j +  (double) j % k;
     System.out.println(
      ++n + ".  (double) i / j +  (double) j % k  \n\t\t\t\t"
        +  dans );
 
     i = 0;   j = 0;    k = 0;
     bans =  (i>j) && !(j>k);
     System.out.println(
      ++n + ".  (i>j) && !(j>k)  \n\t\t\t\t"
        +  bans );
 
     i = 0;   j = 0;    k = 0;
     bans =  (i<j) || (j == k);
     System.out.println(
      ++n + ".  (i<j) || (j == k)  \n\t\t\t\t"
        +  bans );
 
     i = 0;   j = 0;    k = 0;
     bans =  (i<j) && (j < k) && (k-2 == i);
     System.out.println(
      ++n + ".  (i<j) && (j < k) && (k-2 == i)  \n\t\t\t\t"
        +  bans );
 
     i = 0;   j = 0;    k = 0;
     bans =  ((i<j) || (j < k)) && ((i>j) || (j > k));
     System.out.println(
      ++n + ".  ((i<j) || (j < k)) && ((i>j) || (j > k))  \n\t\t\t\t"
        +  bans );
 
     a = 0;   b = 0;
     dans =  (a-b) * (a+b);
     System.out.println(
      ++n + ".  (a-b) * (a+b)  \n\t\t\t\t"
        +  dans );
 
     a = 0;   b = 0;
     dans =  Math.sqrt( a*a + b*b );
     System.out.println(
      ++n + ".  Math.sqrt( a*a + b*b )  \n\t\t\t\t"
        +  dans );
 
     i = 0;   j = 0;
     dans =  Math.pow( i, j ) + Math.pow( j, i );
     System.out.println(
      ++n + ".  Math.pow( i, j ) + Math.pow( j, i )  \n\t\t\t\t"
        +  dans );
 
 
     i = 0;  bans = false;
     if( i == 3 ) { bans = true; }
     System.out.println(
      ++n + ".  if( i == 3 ) { bans = true; } else { bans = false; }"
          + "  \n\t\t\t\t"
        +  bans );
 
     i = 0;  bans = false;
     if( (i > 30) && (i < 32) ) { bans = true; }
     System.out.println(
      ++n + ".  if( (i > 30) && (i < 32) ) { bans = true; } "
          + "  \n\t\t\t\t"
        +  bans );
 } }

up