Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 Output: 3
In Java:
Write a
Ex: If the input is: 7 15 3
Output: 3
Code:
import java.util.Scanner;
public class LabProgram
{
public static int LargestNumber(int num1, int num2, int num3)
{
if(num1 > num2 && num1 > num3)
return num1;
else if(num2 > num3)
return num2;
else
return num3;
}
public static int SmallestNumber(int num1, int num2, int num3)
{
if(num1 < num2 && num1 < num3);
return num1;
else if(num2 < num3)
return num2;
else
return num3;
}
public static void main(String[] args)
{
int a,b,c, largest, smallest;
Scanner sc=new Scanner(System.in);
System.out.println("\nEnter the numbers:");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
largest = LargestNumber(a,b,c);
smallest = SmallestNumber(a,b,c);
System.out.println("\nLargest: "+largest);
System.out.println("Smallest: "+smallest);
}
}
Error: LabProgram.java:20: error: 'else' without 'if' else if(num2 < num3)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images