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

 
 


Yetunde Laniran
Is the answer 35, 35?
1 Answer(s)      2 years and 5 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; }

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 Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.