Skip to Content
avatar image
Former Member

Number Generator

I have been working on this random number generator for a 4th grade class and I can't quite get the second part correct I have this so far:

import java.util.*;

public class gen {

public static void main (String[] args) {

int count, rval;

Random rgen;

rgen = new Random();

for (count = 0; count < 1; ++count) {

rval = rgen.nextInt(101);

System.out.printf(" %d", rval);

}

System.out.println();

}

}

I need the program to answer if your guess is correct. For instance if the number was 62 I would like this to be the result:

Enter your guess: 71

71 is too high.

Enter your quess: 14

14 is too low.

Enter your guess: 23

23 is too low.

Enter your guess: 65

65 is too high.

Enter your quess: 37

37 is too low.

Enter your guess: 44

44 is too low.

Enter your guess: 62

62 is correct. You needed 7 guesses.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Oct 19, 2006 at 09:48 AM

    Hi,

    you are not asking seriously in this IT-professional forum for a solution of a very basic Java homework ?

    If you can't find the answer by doing a bit of Google research you might redecide if you have selected the correct study course.

    Best Regards, Astrid

    Add comment
    10|10000 characters needed characters exceeded