C
Chad
The following code is a stripped down version of a large project. The
question is why do I have to press ctrl z every time to get the
output? That is, say I type the following at the command line
1 - 3
and then press the enter key on my keyboard. I press ctrl z and I get
'The value is 1' . Then I press it again, I get a 'The value is '.
Then I press it again, I get 'The value is -', etc. Ideas on how to
get how get the entire output out at once? Ideally what I would like
to do is when I type in the above, press the enter key, then, after I
press ctrl z, get
The value is 1
The value is
found the minus sign
The value is 3
import java.util.Scanner;
public class hack {
public static int getNextNumber(String [] storeValues) {
String value = null;
int i = 0;
Scanner input = new Scanner(System.in);
while(input.hasNextLine()) {
try {
storeValues[i++] = input.nextLine();
} catch (IllegalStateException e) {
return -1; //EOF
}
}
return 0;
}
public static void main(String[] args) {
String[] values = new String[100];
char[] getNumber;
int value;
int i = 0;
while ( ( value = getNextNumber(values) ) != -1) {
getNumber = values[0].toCharArray();
switch (value) {
case 0: {
System.out.println("The value is " + getNumber);
i++;
break;
}
case '+': {
System.out.println("found plus sign");
i++;
break;
}
case '-': {
System.out.println("found minus sign");
i++;
break;
}
case '*': {
System.out.println("found mult sign");
i++;
break;
}
case '/': {
System.out.println("found division sign");
i++;
break;
}
default: break;
}
}//end while
}//end main()
question is why do I have to press ctrl z every time to get the
output? That is, say I type the following at the command line
1 - 3
and then press the enter key on my keyboard. I press ctrl z and I get
'The value is 1' . Then I press it again, I get a 'The value is '.
Then I press it again, I get 'The value is -', etc. Ideas on how to
get how get the entire output out at once? Ideally what I would like
to do is when I type in the above, press the enter key, then, after I
press ctrl z, get
The value is 1
The value is
found the minus sign
The value is 3
import java.util.Scanner;
public class hack {
public static int getNextNumber(String [] storeValues) {
String value = null;
int i = 0;
Scanner input = new Scanner(System.in);
while(input.hasNextLine()) {
try {
storeValues[i++] = input.nextLine();
} catch (IllegalStateException e) {
return -1; //EOF
}
}
return 0;
}
public static void main(String[] args) {
String[] values = new String[100];
char[] getNumber;
int value;
int i = 0;
while ( ( value = getNextNumber(values) ) != -1) {
getNumber = values[0].toCharArray();
switch (value) {
case 0: {
System.out.println("The value is " + getNumber);
i++;
break;
}
case '+': {
System.out.println("found plus sign");
i++;
break;
}
case '-': {
System.out.println("found minus sign");
i++;
break;
}
case '*': {
System.out.println("found mult sign");
i++;
break;
}
case '/': {
System.out.println("found division sign");
i++;
break;
}
default: break;
}
}//end while
}//end main()