Computer Science Canada

This won't compile, whats wrong with it

Author:  aqazwsx1 [ Sat Feb 21, 2009 8:03 pm ]
Post subject:  This won't compile, whats wrong with it

This lets the user enter a min and max value, then ask the user too enter a number in the min and max number's range.

Java:
    public class Prompter {
   
       public static void main (String [] args) {
     
         int num1,num2,num;
         
        System.out.println ("Enter a min number");
        num1=input.nextInt();
       
        System.out.println ("Enter a max number");
        num2=input.nextInt();
     
         while (num>num1 && num<num2) {
            System.out.println ("Enter a between "+num1+" "+num2);
             num=input.nextInt();
           
         }
       

      }
   }


I got this error :


Prompter.java:8: cannot find symbol
symbol : variable input
location: class Prompter
num1=input.nextInt();
^
Prompter.java:11: cannot find symbol
symbol : variable input
location: class Prompter
num2=input.nextInt();
^
Prompter.java:15: cannot find symbol
symbol : variable input
location: class Prompter
num=input.nextInt();
^
3 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.


Can anyone help? Thanks!

Author:  btiffin [ Sat Feb 21, 2009 8:53 pm ]
Post subject:  Re: This won't compile, whats wrong with it

aqazwsx1;

Google java.io.InputStreamReader and java.util.Scanner for some hints.

Cheers

Author:  SJ [ Sat Feb 21, 2009 9:31 pm ]
Post subject:  RE:This won\'t compile, whats wrong with it

just wondering, is "input" something built into jGRASP?

maybe you'd like to put

Scanner input = new Scanner(System.in);

at the beginning?

Author:  mono-1-rulz [ Sat Feb 21, 2009 9:37 pm ]
Post subject:  Re: This won't compile, whats wrong with it

First....have you imported the Scanner class from thee java libraries??
u hv to import it to use it.....
try typing this at the beginning(even before the class statement):

import java.util.Scanner ;

Then u should probably create an object called input before using it......use the statement SJ wrote.

Then it should work . Very Happy

Author:  aqazwsx1 [ Sat Feb 21, 2009 11:00 pm ]
Post subject:  RE:This won\'t compile, whats wrong with it

ok thanks everyone! Very Happy


: