English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

(Is class the right term)

here's what i got:

import java.util.Random;
import java.util.Scanner;

public class Decisions
{

public static void main (String[] args)
{

Random generator = new Random();
Scanner scanner;

int value = generator.nextInt(100) + 1;
int guess = 0;

System.out.println("Enter an integer between 1 and 100 (integers 1\n" +
"and 100 are okay too) and press enter:" );


//HERE LIES THE PROBLEM:
guess = scanner.nextInt();
//


}
}



I want the user to be able to type in a number and press enter.

How do i fix the problem line? Please tell me if you need more details.

Thanks.

2006-10-12 18:45:36 · 2 answers · asked by larkale07 2 in Computers & Internet Programming & Design

on further review it may be "Scanner scanner;", line 11 that's causing the problem.

2006-10-12 18:56:21 · update #1

2 answers

you need to complete your scanner deceleration you need:
Scanner scanner = new Scanner(System.in);

the rest looks good

2006-10-12 19:07:51 · answer #1 · answered by Brady 3 · 0 0

may be this is what u want

import java.util.Random;
import java.util.Scanner;

public class Decision {
public static void main (String[] args){
Random generator = new Random();
Scanner scanner;
int value = generator.nextInt(100) + 1;
int guess = 0;

System.out.println("Enter an integer between 1 and 100 (integers 1\n" +
"and 100 are okay too) and press enter:" );
//HERE LIES THE PROBLEM:
scanner = new Scanner(System.in);
guess = scanner.nextInt();
System.out.println(guess);
}
}

PS: this is acceptin all integers no restriction takencare

2006-10-12 19:09:46 · answer #2 · answered by Franzi 1 · 0 0

fedest.com, questions and answers