Showing posts with label smaller number. Show all posts
Showing posts with label smaller number. Show all posts

Friday, June 5, 2020

Write a program in java to find Smallest Number in three number using conditional operator.

14)  Write a program in java to find Smallest Number in three number using   conditional operator.

import java.util.*;
public class Smaller_in_three_using_conditional_operator
{ public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter three numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = (a<b) ? (a<c)?a:c : (b<c)?b:c ;
        System.out.println("Smaller num = "+d);
    }
}

Write a program in java to find Smallest Number in three number using if else statement.

12)  Write a program in java to find Smallest Number in three number using if else statement.

import java.util.*;

public class Smaller_in_three_using_if_else

{

     public static void main(String args[ ])

    {

        Scanner sc = new Scanner (System.in);

        System.out.println("Enter three numbers");

        int a = sc.nextInt();

        int b = sc.nextInt();

        int c = sc.nextInt();

        if(a<b&&a<c)

        {

             System.out.println("Smaller number = "+a);

        }

        else if(b<a&&b<c)

        {

            System.out.println("Smaller number = "+b);

        }

        else

        {

            System.out.println("Smaller number = "+c);

        }

    }

}


Thursday, June 4, 2020

Write a program in java to input two numbers and find the Smaller Number using if else.

6)  Write a program in java to input two numbers and find the Smaller Number using if else.

import java.util.*;
public class Smaller_using_if_else
{
    public static void main( String args[ ] )
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b)
        {
             System.out.println("Smaller number = "+a);
        }
        else
        {
            System.out.println("Smaller number = "+b);
        }
    }
}

 jhvghvgk ;nkjn ,nkjhj