我得到总和,平均值和产品。我面临的真正困难是最小和最大的数字。
我可以用两个数字来做,但是三个数字对我没有任何意义。问我,我的问题是否清楚或者是否有意义。
import java.util.Scanner;
// exercise 2.17
public class ArithmeticSmallestLargest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num1;
int num2;
int num3;
int sum;
int average;
int product;
double largest
System.out.print("Enter First Integer: ");
num1 = input.nextInt();
System.out.print("Enter Second Integer: ");
num2 = input.nextInt();
System.out.print("Enter Third Integer: ");
num3 = input.nextInt();
sum = num1 + num2 + num3;
average = sum / 3;
product = num1 * num2 * num3;
if (largest =num1 > num2 & num2 > num3)
System.out.println(sum);
System.out.println(average);
System.out.println(product);
System.out.println("The biggest number is " + largest);
}
}
答案 0 :(得分:1)
import java.util.Scanner;
// exercise 2.17
public class ArithmeticSmallestLargest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num1;
int num2;
int num3;
int sum;
int average;
int product;
int largest;
int smallest;
System.out.print("Enter First Integer: ");
num1 = input.nextInt();
System.out.print("Enter Second Integer: ");
num2 = input.nextInt();
System.out.print("Enter Third Integer: ");
num3 = input.nextInt();
sum = num1 + num2 + num3;
average = sum / 3;
product = num1 * num2 * num3;
largest = num1;
smallest = num1;
if(num2 > largest)
largest = num2;
if(num3 > largest)
largest = num3;
if(num2 < smallest)
smallest = num2;
if (num3 < smallest)
smallest = num3;
System.out.println("The sum is " + sum);
System.out.println("The average is " + average);
System.out.println("The product is " + product);
System.out.println("Largest of three integers is " + largest + " and the smallest is "+ smallest + ".");
}
}
答案 1 :(得分:0)
for element1 in list_of_elements:
for element2 in list_of_elements:
if not element1 == element2:
#do
答案 2 :(得分:-1)
import java.util.Scanner;
public class ArithmeticSmallestLargest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num1;
int num2;
int num3;
int sum;
int average;
int product;
int largest;
int smallest;
System.out.print("Enter First Integer: ");
num1 = input.nextInt();
System.out.print("Enter Second Integer: ");
num2 = input.nextInt();
System.out.print("Enter Third Integer: ");
num3 = input.nextInt();
sum = num1 + num2 + num3;
average = sum / 3;
product = num1 * num2 * num3;
largest = num1;
smallest = num1;
if(num2 > largest)
largest = num2;
if(num3 > largest)
largest = num3;
if(num2 < smallest)
smallest = num2;
if (num3 < smallest)
smallest = num3;
System.out.printf("The sum is %d%n " , sum);
System.out.printf("The average is %d%n " , average);
System.out.printf("The product is %d%n " , product);
System.out.printf("Largest of three integers is %d%n " , largest);
System.out.printf("Smallest of three integers is %d%n " , smallest);
}
}
答案如下:
输入第一整数:60
输入第二个整数:90
输入第三整数:30
总和是180
平均是60
产品是162000
三个整数最大为90
三个整数中最小的是30
...程序退出代码为0
按ENTER退出控制台。