Until Zero

Write a program to input numbers as long as user doesn't give zero.Find the greatest and smallest number, swap the values of both variable without using the third variable.

import java.util.Scanner;
class UntilZero
{
    public static void main()
    {
        int x,max,min;
        System.out.println("Enter an integer");
        Scanner in = new Scanner(System.in);
        x = in.nextInt();
        max=min=x;
        while(x!=0)
        {
            System.out.println("Enter an integer again");
            x = in.nextInt();
            if(x>max)
                max=x; //stores maximum
            if(x<min)
                min=x; //stores minimum
        }
        System.out.println("Maximum Value  "+ max );
        System.out.println("Minimum Value  "+ min );
        max = max + min;
        min = max - min;
        max = max - min;
        System.out.println("\n\nAfter Swaping Without Third Variable ");
        System.out.println("Maximum Value  "+ min );
        System.out.println("Minimum Value  "+ max );
    }
}


For any desired program, please comment below. We will try our best to make that program available.

Comments

Popular Posts