Write a function that calculates the smallest of three numbers.
Hint:
You must write the body of the existing function min.
Requirements:
The program must display text on the screen.
The method min must not display any text on the screen.
The method main must call the method min four times.
The main method must display the result of the min method. The record should be on a separate line each time.
The min method must return the smallest number from the numbers a, b and c.
with the given code(screenshot)
I tried rewriting it on my own
public class Solution {
public static int min(int a, int b, int c) {
//write your code here makes no sense as b<c unnecessary (a < b && b < c)
int m1;
if (a<b)
return a;
else
return b;
b= m1;
// b is smaller than a but it is also smaller than c
// ? a was not tested against c now
if (m1< c)
return m1;
else
return c;
}
public static void main(String[] args) throws Exception {
System.out.println(min(1, 2, 3));
System.out.println(min(-1, -2, -3));
System.out.println(min(3, 5, 3));
System.out.println(min(5, 5, 10));
}
}
but that didn´t work out
I would really appreciate it if someone could rewrite the following solution for me with if and else which is apparently a replacement for the symbols " ? and : "
