diff --git "a/42 \346\226\271\345\242\236\345\205\264/20221218\344\270\211\344\270\252\346\225\260\346\261\202\347\253\213\346\226\271\345\222\214 and \346\257\224\350\276\203\344\270\244\344\270\252\346\225\260.md" "b/42 \346\226\271\345\242\236\345\205\264/20221218\344\270\211\344\270\252\346\225\260\346\261\202\347\253\213\346\226\271\345\222\214 and \346\257\224\350\276\203\344\270\244\344\270\252\346\225\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..7608b57961a3682c239dbfa3e7c1339c313271b2 --- /dev/null +++ "b/42 \346\226\271\345\242\236\345\205\264/20221218\344\270\211\344\270\252\346\225\260\346\261\202\347\253\213\346\226\271\345\222\214 and \346\257\224\350\276\203\344\270\244\344\270\252\346\225\260.md" @@ -0,0 +1,41 @@ +```java +import java.util.Scanner; +public class m18 { + //在主函数中从键盘接收X,Y,Z三个数,编写函数计算这三个数的立方和并返回计算结果:SUM = X+Y+Z + public static void main(String[] args) { + System.out.println("三位数立方求和"); + System.out.println("请输入第一个数字:"); + Scanner sc = new Scanner(System.in); + int x = sc.nextInt(); + System.out.println("请输入第二个数字:"); + int y = sc.nextInt(); + System.out.println("请输入第三个数字:"); + int z = sc.nextInt(); + int sum = (int) (Math.pow(x, 3) + Math.pow(y, 3) + Math.pow(z, 3)); + System.out.println("此时三位数的总和为:" + sum); + System.out.println("------------------------------------------------------------------------"); + Scanner sc1 = new Scanner(System.in); + System.out.println("请输入第一个要比较的数:"); + int c = sc1.nextInt(); + System.out.println("请输入第二个要比较的数:"); + int d = sc1.nextInt(); + int compare = compare(c, d); + System.out.println(compare); + + + } +//定义一函数,用于求2个数中最大值,并将其返回,这2个数在主函数中有用户输入。 + public static int compare(int a, int b) { + if (a > b) { + System.out.println("此时最大值是:" + a); + System.out.println("此时记录数值:" + a); + return a; + } else { + System.out.println("此时最大值是" + b); + System.out.println("此时记录数值:" + b); + return b; + } + } +} +``` +