write a program in java to input 3 numbers and print the second smallest number
Answers
Answered by
2
Answer:
package Brainly;
import java.util.*;
public class smallest
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter 3 numbers");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if((a>b&&b>c)||(c>b&&b>a))
System.out.println("Second smallest = " + b);
else if((b>c&&c>a)||(a>c&&c>b))
System.out.println("Second smallest = " + c);
else
System.out.println("Second smallest to = " + a);
}
}
••Required Output Attached.
Explaination:-
- The program is accepting 3 numbers as input(a,b,c)
- If condition part Checks which number is second smallest
- finally, smallest number is printed.
Attachments:
Similar questions