This is driving me insane! Here's the code:
public static void main(String[] strings) {
int input;
String source;
TextIO.putln("Please enter the shift value (between -25..-1 and 1开发者_如何转开发..25)");
input=TextIO.getInt();
while ((input < 1 || input > 25) && (input <-25 || input >-1) && (input != 999 && input !=-999))
{
TextIO.putln(input + " is not a valid shift value.");
TextIO.putln("Please enter the shift value (between -25..-1 and 1..25)");
input=TextIO.getInt();
}
TextIO.putln("Please enter the source text (empty line to quit)");
//TextIO.putln(source);
source = TextIO.getln();
TextIO.putln("Source :" + source);?");
}
}
However, its telling me that 'source' is never read! It's not allowing me to get input! Can anyone see what the problem may be?
The compiler is correct; the variable source
is never read. You're assigning a value to it (source = TextIO.getln();
), but you're never reading that value back out.
To do so, you could do something like:
TextIO.putln(source);
You seem to be having trouble reading text from the console with the TextIO
class. Here's a more standard approach, introduced in Java 5:
String source;
Scanner in = new Scanner(System.in);
source = in.nextLine();
What exactly do you wish to do with the variable source
? As it stands, you're asking the user to enter a string, but you're not doing anything with that string.
You should probably ask one of your friends for help instead of posting our homework online. I feel as though this is subjective to cheating. If you are having trouble already, it is only going to get worse. You should be breezing through your freshman year.
精彩评论