Menu
Question Index
...

What will be the output of the following program?

public class SumOfOddAndEvenDigitsInNumber
{
    public static void main(String args[])
    {
        int number = 1235689012;
        int value1 = 0;
        int value2 = 0;
        while (number > 0)
        {
            if ((number % 10) % 2 == 0)
                value1 = value1 + number % 10;
            else
                value2 = value2 + number % 10;
            number = number / 10;
        }
        System.out.print("Value1 : " + value1 + " Value2 : " + value2);
    }
}


Value1 : 18 Value2 : 19
Value1 : 10 Value2 : 19
Value1 : 28 Value2 : 11
Value1 : 31 Value2 : 10
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java for loops vs Java while loops vs Java do while loops

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App