5 java program code

timer Asked: Nov 6th, 2014

Question description


I need answers for these java questions please read them before you offer  : 

 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, separated by the word "and".  For example, the factors of the number 24 should print as the following : (2-credit)

1 and 2 and 3 and 4 and 6 and 8 and 12 and 24

You assume that the parameter's value is greater than 0, or you may throw an exception if is is 0 or negative.

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

  within main(),



  ...  // test the method with any other numbers...

  5. Write a method called hasAnOddDigit() that returns whether a given positive integer has a least one digit whose value is odd. Return true if the number has at least one odd digit and false if none of its digits are odd. For example, the callhasAnOddDigit(4882216) should return true and hasAnOddDigit(6248) should return false. (2-credit)

  You may include the method, hasAnOddDigit()within the previous class, TestNumbers, or write a new class. 

Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors