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
sourceis 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
TextIOclass. Here’s a more standard approach, introduced in Java 5: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.