system doesn´t end once I enter -1 in the console how can I change that

`´import java.io.*; public class Solution { public static void main(String[] args) throws Exception { BufferedReader intro = new BufferedReader(new InputStreamReader(System.in)); int a = Integer.parseInt(intro.readLine()); int c = Integer.parseInt(intro.readLine()); int b = Integer.parseInt(intro.readLine()); while(a==-1 || b == -1 | c==-1 ) { if (a == -1) { System.out.println(a);
} else if (c == -1) { System.out.println(a + c); } else if (b == -1){ System.out.println(a + c + b); // ansonsten geht es endlos weiter } break; //Problem system doesn´t end once I enter -1 in the console how can I change that }``
3 Replies
JavaBot
JavaBot20h ago
This post has been reserved for your question.
Hey @blue! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
import java.io.*;

public class Solution {
public static void main(String[] args) throws Exception {


BufferedReader intro = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(intro.readLine());
int c = Integer.parseInt(intro.readLine());
int b = Integer.parseInt(intro.readLine());

while(a==-1 || b == -1 | c==-1 ) {
if (a == -1) {
System.out.println(a);


}

else if (c == -1) {
System.out.println(a + c);

}

else if (b == -1){
System.out.println(a + c + b);
// ansonsten geht es endlos weiter
}
break;
//Problem system doesn´t end once I enter -1 in the console how can I change that
}``
import java.io.*;

public class Solution {
public static void main(String[] args) throws Exception {


BufferedReader intro = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(intro.readLine());
int c = Integer.parseInt(intro.readLine());
int b = Integer.parseInt(intro.readLine());

while(a==-1 || b == -1 | c==-1 ) {
if (a == -1) {
System.out.println(a);


}

else if (c == -1) {
System.out.println(a + c);

}

else if (b == -1){
System.out.println(a + c + b);
// ansonsten geht es endlos weiter
}
break;
//Problem system doesn´t end once I enter -1 in the console how can I change that
}``
dan1st
dan1st20h ago
you used | instead of || -1 | c does a bitwise or on -1 and c and the result of a bitwise or with -1 is always -1 Also while loops work by looping as long as the condition is fulfilled not until it is fulfilled
JavaBot
JavaBot14h ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server