## 5 java program code

Hello!

1.Write an interactive program that repeatedly prompts the user to enter a number and, once the number -1 is typed, displays the miximum and minimun numbers that the user entered. Here is a sample dialogue: (2-credit)

Type a number (or -1 to stop) : 90

Type a number (or -1 to stop) : 25

Type a number (or -1 to stop) : 17

Type a number (or -1 to stop) : 15

Type a number (or -1 to stop) : -1

Maximum was 90

Minimum was 15

Average is  36.75

If -1 is the first number typed, no maximum or minimum should be printed. The dialogue would look like this.

Type a number (or -1 to stop) : -1

2. Consider the following variable declarations: (2-credit)

int x = 20;

int y= -1;

int z = 11;

boolean a = true;

boolean b = false;

What is the value of each of the following Boolean expressions?

1)  !a

2)  a || b

3)  (x>y) && (y>z)

4)  (x==y) || (x>=z)

5)  !(x%3!=0) && a

6)  !(x/2 == 10) || (a&&b) || (z%5 == 1)

7)  a || true

8)  (x<0) || (y>=0)

9)  b || !b

10) b && !b

3. Using “Boolean Zen,” write an improved (simplified) version of the following method, which returns whether the given String starts and ends with the same character: (2-credit)

public static boolean startEndSame(String str) {

if (str.charAt(0) == str.charAt(str.length()-1)) {

return true;

} else {

return false;

}

} // end of startEndSame()

To submit, write a class, TestWords, which contains main() and startEndSame(). The main() method should call startEndSame() method as follows:

within main(),

System.out.println(“”pop”” returns “” + startEndSame(“”pop””));

System.out.println(“”””top”” returns “” + startEndSame(“”top””));

System.out.println(“”””erase”” returns “” + startEndSame(“”erase””));

System.out.println(“”””stars”” returns “” + startEndSame(“”stars””));

…  // test the method with any other words…

4. Write a method called printFactors() that accepts an integer as its parameter and uses a fencepost loop to print the factors of that number