4
Hello, I’m trying to solve the following problem below:
However, I am having trouble putting this EOF condition in java. Here on stack I found attempts solutions, but they are related to using files, and for my problem I’m not using a file.
For example:
while (fileReader.nextLine() != null) {
String line = fileReader.nextLine();
System.out.println(line);
}
But this is with the use of file, which is not my case.
My problem is to represent this EOF in java. It follows the part of my code that I am in trouble:
public class Main {
public static void main(String[] args) {
while(?){ //Condição de parada EOF
... código ...
}
If I remember correctly, in C I could do something like...
while (number != EOF);
But how can I do it in java?
I solved the problem in C, stay like this:
int main(){
int N = 0;
while(scanf("%d",&N) != EOF){
... código ...
}
But I would like to solve in java, so far I’m no solution, some hint?
the stop condition would not be the input number you indicated? 4 or 7 for example? In this case you could put a counter inside the while that increases until you reach the number, and when the number is greater or equal to the stop condition, it stops while. int counter = 0; while(fieldNumber > counter){ counter ++; }
– Geferson
@Geferson, no, 4 and 7 represent the dimension of the matrix. From what I understood of the problem my program should receive several entries, like: 4 7 8 10 50 ... And the stopping criterion is EOF. So after all the entrances have passed, I must print out all the respective matrices. But I did not understand how I should make this stop criterion, IE, how to represent this EOF.
– Filipi Maciel