diff --git "a/16 \351\230\231\350\213\217\346\226\207/20221217 java\346\226\271\346\263\225.md" "b/16 \351\230\231\350\213\217\346\226\207/20221217 java\346\226\271\346\263\225.md" new file mode 100644 index 0000000000000000000000000000000000000000..81da72f216faa4a0d6d5f31a2b4ae8906111d096 --- /dev/null +++ "b/16 \351\230\231\350\213\217\346\226\207/20221217 java\346\226\271\346\263\225.md" @@ -0,0 +1,60 @@ +# 笔记 + +1.语法格式 + +```java +public static void 方法名 ( ) { +// 方法体; +} + +``` + +返回值类型:基本类型、引用类型、void(无返回值) + +关于参数:在调用时,叫实际参数。在定义时,叫形式参数。 + +# 作业 + +```java +import java.util.Scanner; +//3. 定义一函数,用于求2个数中的较大数,并将其返回,这2个数字在主函数中由用户输入 +public class D10 { + public static void main(String[] args) { + Scanner cs=new Scanner(System.in); + System.out.println("请输入数字1"); + int a= cs.nextInt(); + System.out.println("请输入数字2"); + int b= cs.nextInt(); + int c=msm(a,b); + System.out.println("最大值是:"+c); + } + public static int msm(int a,int b){ + return a>b?a:b; + } +} +``` + +```java +import java.util.Scanner; + +public class D11 { + public static void main(String[] args) { + //4. 在主函数中从键盘接收X, Y , Z3个数, + // 编写函数计算这3个数的立方和并返回计算结果:S=X3+Y3+Z3 + Scanner cs=new Scanner(System.in); + System.out.println("请输入X"); + int x= cs.nextInt(); + System.out.println("请输入Y"); + int y= cs.nextInt(); + System.out.println("请输入Z"); + int z= cs.nextInt(); + int a=getSum(x,y,z); + System.out.println("立方和是:"+a); + + } + public static int getSum(int x,int y,int z){ + return x=x*x*x+y*y*y+z*z*z; + } +} +``` +