I have created a while loop that takes in a user value b and checks for two conditions. Although I got my code right I originally tried to do this with a single while loop combining the two conditions but it didn't work. My incrementer i++ either counts once or loops forever depending on where I put it.
Is there a way that this could work using a while statement combining the conditions?
Does not work
//Declare variables
int i = 0 ; //Counter Variable.
int positive = 0 ; //Holds the result of our positive sum.
while ( ( i < b ) && ( i % 10 == 0 ) ) //While i is less than the users number.
{
positive = i ;
System.out.println ( positive ) ;
i++ ; //Incrementer
}
This Works
//Declare variables
int i = 0 ; //Counter Variable.
int positive = 0 ; //Holds the result of our positive sum.
while ( i < b ) //While i is less than the users number.
{
if ( i % 10 == 0 )
{
positive = i ;
System.out.println ( positive ) ;
}
i++ ;
}
b