Menu
Question Index
...

What will be the output of the following program?

public class MinMaxDigitInNumber
{
    public static void main(String args[])
    {
        int number = 1235689012;
        range(number);
    }
    private static void range(int number)
    {
        int value1 = 0;
        int value2 = 0;
        for (value1 = value2 = number % 10; number > 0; number = number / 10)
        {
            if (value1 > number % 10)
            {
                value1 = number % 10;
            }
            if (value2 < number % 10)
            {
                value2 = number % 10;
            }
        }
        System.out.print("Value1 : " + value1 + "  Value2 : " + value2);
    }
}


Value1 : 8  Value2 : 9
Value1 : 1  Value2 : 2
Value1 : 0  Value2 : 9
Value1 : 9  Value2 : 0
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Methods - Parameter Passing And Scope

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App