hi
Got 2 questions.
1.How can i simplify 4 variables all with same condition?
if a,b,c,d <1 System.out.println("Invalid input");?
How to put this in a simple code?I know it can be done individually.

2.if the above condition is false i dont want my code to go further and calculate the input.How and i able to do this.Presently everytime i enter an invalid number ,it still processes the output but also come up with the statement"invalid number".

Thank you

write the code as below:

if(a < 1 || b < 1 || c < 1 || d || 1)
{     
     System.out.print("Invalid Input");
     break;
}

.if the above condition is false i dont want my code to go further and calculate the input.How and i able to do this.Presently everytime i enter an invalid number ,it still processes the output but also come up with the statement"invalid number".

If you want to straight away exit your program you will have to use exit() inside if statement. If you are in a loop and simply want to get out of the loop then you will have to use break as mentioned by adil bashir

if(a < 1 || b < 1 || c < 1 || d || 1)
{
System.out.print("Invalid Input");
break;
}

You need to decide whether you want to use '&&' or '||' depending on what condition you wan to check. If you are looking for any one of a,b,c,d to be < 1 then above code using or condition is fine . If your condition is true when all a,b,c,d < 1 , then you will have to use and (&&) instead

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.