Gametask
unknown
java
3 years ago
1.3 kB
61
Indexable
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// read in the three-digit number from the user
System.out.print("Enter a three-digit number: ");
int number = input.nextInt();
// extract the three digits from the number
int hundreds = number / 100;
int tens = (number / 10) % 10;
int ones = number % 10;
// calculate the maximum value that can be obtained
int maxResult = 0;
int tempResult = ones * tens + hundreds;
if (tempResult > maxResult) {
maxResult = tempResult;
}
tempResult = ones * tens * hundreds;
if (tempResult > maxResult) {
maxResult = tempResult;
}
tempResult = ones + tens + hundreds;
if (tempResult > maxResult) {
maxResult = tempResult;
}
tempResult = ones + tens * hundreds;
if (tempResult > maxResult) {
maxResult = tempResult;
}
tempResult = ones * hundreds + tens;
if (tempResult > maxResult) {
maxResult = tempResult;
}
// print the maximum value
System.out.println(maxResult);
}
}Editor is loading...