jeudi 24 septembre 2015

Is there anything like && that would work for integers in if statements? [duplicate]

This question already has an answer here:

Hey guys I know that you can't use && in if statements because it's meant to be for booleans, but is there anything that I could use in an if statement that would work with integers? Here's what I have now:

                import java.util.Scanner;
                public class Lab5ptC {

                public static void main(String[] args) {
                       Scanner  scanner = new Scanner(System.in);

                       int a = scanner.nextInt();
                       int b = scanner.nextInt();
                       int c = scanner.nextInt();
                       int sum = a+b+c;

                       while(sum!=0){
                           if(sum == 0){

                           System.out.println("This program has ended.");
                           }else{
                                sum = a + b + c;
                                System.out.println("The sum is "+ sum);
                                if(???){}
                   }        
                   }
                   }
                   }

My goal from here is to end the program if the person enters in 0 three times when prompt (I haven't used a println for a prompt yet, but I can add that once I get the rest functioning because it's easy). Sum will never be zero for all practical purposes (I suppose if you wrote everything you entered as a negative number it might). So, any suggestions?

P.S. I realize that it's formatted funny on this.. I've never posted code here (at least not this much) before so sorry about that.

Aucun commentaire:

Enregistrer un commentaire