Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#1. Operators and values, expressions Please correct the following code to make

ID: 3882295 • Letter: #

Question

#1. Operators and values, expressions

Please correct the following code to make it print the given expressions and their answers well (3pts).

public class DataTypes {

   public static void main(String[] args) {

      System.out.println("5*8/6 = " + 5*8/6);

      System.out.println("(2*6)+(4*4)+10 = " + (2*6)+(4*4)+10);

      System.out.println("6 / 2 + 7 / 3 = " + 6 / 2 + 7 / 3);

      System.out.println("6 * 7 % 4 = " + 6 * 7 % 4 );

      System.out.println("22 + 4 * 2 = " + 22 + 4 * 2);

   }

}

#2. String Concatenation

Please practice the following string expressions manually and compare your answers with the computer generated strings. Submit the code with answers embedded in the code as comments (3pts).

public class Evaluation {

   public static void main(String[] args) {

      System.out.println("Hello, world!");

      System.out.println("Hello " + "World!");

      System.out.println("Summer " + 2017);

      System.out.println("Interstate " + 9 + 5);

      System.out.println(20 + 20 + " Class");

      System.out.println("Class " + 20 + 20);

   }

}

#3. for-loop and a method declaration

Please write a program which invokes a method, drawBox(6). The drawBox(int num) method prints the following figure: (3pts)

*****1

****22

***333

**4444

*55555

666666

#4. for-loop and a method declaration

Please write a method which recevies an integer N as its parameter and prints N different number of odd numbers increasing order starting from 1 like the following sequence of numbers. The method can be invoked from the main() method in the previous question (#3) (3pts).

      The expected output: 1   3   5   7   9   11

The method is invoked like the following statement:

      printOddNumbers(6);   // This method is to print 6 increasing order of odd numbers starting from 1.

#5. Variables and a method declaration

Please write a method which returns the slope of the line between the given points: Point1 (x1, y1) and Point2 (x2, y2) (3pts).

Public static double slope (int x1, int y1, int x2, int y2) {

}

Explanation / Answer

Hi I have answered first 3 questions.

Please repost others in separate post

1.

public class DataTypes {

   public static void main(String[] args) {

       System.out.println("5*8/6 = " + (5*8/6));

       System.out.println("(2*6)+(4*4)+10 = " + ((2*6)+(4*4)+10));

       System.out.println("6 / 2 + 7 / 3 = " +( 6 / 2 + 7 / 3));

       System.out.println("6 * 7 % 4 = " + (6 * 7 % 4) );

       System.out.println("22 + 4 * 2 = " +( 22 + 4 * 2));

   }

}

/*

Output:

5*8/6 = 6

(2*6)+(4*4)+10 = 38

6 / 2 + 7 / 3 = 5

6 * 7 % 4 = 2

22 + 4 * 2 = 30

*/

2.

public class Evaluation {

   public static void main(String[] args) {

       System.out.println("Hello, world!"); // output : Hello, world!

       System.out.println("Hello " + "World!"); // output: Hello World!

       System.out.println("Summer " + 2017); // output Summer 2017

       System.out.println("Interstate " + 9 + 5); // output: Interstate 95

       System.out.println(20 + 20 + " Class"); // output: 40 Class

       System.out.println("Class " + 20 + 20); // output: Class 2020

   }

}

3)

public void drawBox(int num) {

      

       for(int i=1; i<=num; i++) {

          

           for(int j=1; j<=(num-i); j++) {

               System.out.print("*");

           }

           for(int k=1; k<=i; k++)

               System.out.print(i);

           System.out.println();

       }

   }