Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter1: Fundamentals Of C++ Programming
Section1.3: Preliminary Three: Software Development
Problem 6E
icon
Related questions
Question
100%

Problem: 

 

9.20 LAB: Max and min numbers

 

Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values.

Ex: If the input is:

7 15 3

the output is:

largest: 15 smallest: 3

Your program must define and call the following two methods. The method largestNumber() should return the largest number of the three input values. The method smallestNumber() should return the smallest number of the three input values.
public static int largestNumber(int num1, int num2, int num3)
public static int smallestNumber(int num1, int num2, int num3)

 

Java code: 

 

import java.util.Scanner;

public class LabProgram {

/* Define your method here */public static int largestNumber(int num1, int num2, int num3) {
int largest;

if ((num1 > num2) && (num1> num3)) {
largest=num1;
} else if (num2 > num3 && num2 > num1)
largest=num2;
} else {
largest=num3;
}
return largest;
}

public static int smallestNumber(int num1, int num2, int num3
int smallest;

if ((num1 < num2) && (num1< num3)) {
smallest=num1;
} else if (num2 < num3 && num2 < num1)
smallest=num1;
} else {
smallest=num1;
}
return smallest;
}

public static void main(String[] args) {
/* Type your code here. */Scanner scnr = new Scanner(System.in);
user1=scnr.nextInt();
user2=scnr.nextInt();
user3=scnr.nextInt();


System.out.print("largest: " +largestNumber);
System.out.print("smallest: " +smallestNumber);
}
}

 

My errors:

LabProgram.java:12: error: illegal start of type
} else {
^
LabProgram.java:15: error: illegal start of type
return largest;
^
LabProgram.java:15: error: <identifier> expected
return largest;
^
LabProgram.java:18: error: class, interface, or enum expected
public static int smallestNumber(int num1, int num2, int num3
^
LabProgram.java:21: error: class, interface, or enum expected
if ((num1 < num2) && (num1< num3)) {
^
LabProgram.java:23: error: class, interface, or enum expected
} else if (num2 < num3 && num2 < num1)
^
LabProgram.java:25: error: class, interface, or enum expected
} else {
^
LabProgram.java:27: error: class, interface, or enum expected
}
^
LabProgram.java:29: error: class, interface, or enum expected
}
^
LabProgram.java:31: error: class, interface, or enum expected
public static void main(String[] args) {
^
LabProgram.java:33: error: class, interface, or enum expected
user1=scnr.nextInt();
^
LabProgram.java:34: error: class, interface, or enum expected
user2=scnr.nextInt();
^
LabProgram.java:35: error: class, interface, or enum expected
user3=scnr.nextInt();
^
LabProgram.java:39: error: class, interface, or enum expected
System.out.print("largest: " +largestNumber);
^
LabProgram.java:40: error: class, interface, or enum expected
System.out.print("smallest: " +smallestNumber);
^
LabProgram.java:41: error: class, interface, or enum expected
}
^
16 errors

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning