im having a problem in my java exercice the question is saying The program will end when the sum of even is >= 50 or the sum of odd is >= 49.
so while solving it i tried to use
while (sumeven < 50 || sumodd < 49 )
and it didnt worked at all but when i checked the solution they use
while (evensum <= 50 && oddsum<=49)
and it worked ( gave same answeres like the sample run)
so my question is did i misunderstood it ? or the question have some kind of a wrong given. thank you for your time
update:
the code :
package sample2;
import java.util.Scanner;
public class Sample2 {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("enter the initial value");
int sumeven=0;
int sumodd=0;
int num;
int initial;
int div5and2=0;
initial=scan.nextInt();
if (initial<=0)
System.out.println("the number must be strictly positive");
else{
if (initial%2==0)
sumeven=initial;
else
sumodd=initial;
System.out.println("start entering your numbers");
num=scan.nextInt();
if (num<=0)
System.out.println("the number must be strictly positive");
else{
while(sumeven<=50||sumodd<=49 )
{
if (num%2==0)
sumeven=sumeven+num;
else
sumodd=sumodd+num;
if (num%5==0 &&num%2==0)
div5and2=div5and2+1;
num=scan.nextInt();
while(num<=0)
{
System.out.println("the number must be strictly positive");
num=scan.nextInt();
}
}
System.out.println("the sum of even numbers: "+sumeven);
System.out.println("the sum of odd numbers: "+sumodd);
System.out.println("the number of integers divided by 2 and 5: "+div5and2);
}
}
}
}