Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Is the answer 35, 35?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Yetunde Laniran
Is the answer 35, 35?
1 Answer(s)      3 years and 10 months ago
Posted in : Java Beginners


int a = 5; int b = 7; int num = 35; while (a < b) { System.out.println(?My age is ? + num); a = a + 1; }


Advertisement
View Answers

December 23, 2010 at 1:08 PM


Hello Friend,

class Check{
    public static void main(String[] args) 
    {
        int a = 5;
        int b = 7;
        int num = 35;
        while (a < b) { 
        System.out.println("?My age is ? "+ num);
        a = a + 1;
        }
    }
}

The above program outputs: My age is ? " 35 My age is ? " 35

As you have created a condition that a should be less than b.And you have specified a=5 and b=7.So firstly it takes the value of a 5 and check the condition and returns 35. Then it checks the incremented value i.e a+1, it is also less than 7 so it returns 35. Then again it checks but this time value will be 8 which is larger than b i.e. 7 so the loop ends here.

Thanks

Thanks



Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com