Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 This won't compile, whats wrong with it
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aqazwsx1




PostPosted: 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!
Sponsor
Sponsor
Sponsor
sponsor
btiffin




PostPosted: 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
SJ




PostPosted: 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?
mono-1-rulz




PostPosted: 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
aqazwsx1




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

ok thanks everyone! Very Happy
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: