程序的结构分三种:一、顺序结构 二、分支结构 三、循环结构顺序结构有四种类型:无参无返、有参无返、无参有返、有参有返下面分别用这四种类型来计算1+2=多少?02018测试开发平台官方中文Eclipse安装配置32018新手如何使用eclipse工具进行编码(一)02018新手如何使用eclipse工具进行编码(二)
工具/原料
1
eclipse工具
2
JDK-java开发工具包
方法/步骤
1
public class Type { // main方法// 1,2叫实参 public static void main(String[] args) { sx1(); sx2(1, 2); int t = sx3() + 1; System.out.println(t); int f = sx4(1, 2); System.out.println(f); }
2
// 类型一:无参无返 public static void sx1() { int a = 1; int b = 2; int c = a + b; System.out.println(c); }
3
// 类型二:有参无返// a,b叫形参 public static void sx2(int a, int b) { int c = a + b; System.out.println(c); }
4
// 类型三:无参有返 public static int sx3() { int a = 1; int b = 2; int c = a + b; return c; }// 返回值为c,作用:整个方法运行的结果都存放在c里(有了返回值就可以拿到程序运行的结果)
5
// 类型四:有参有返 public static int sx4(int a, int b) {int c = a + b; return c; }
注意事项
1
没有return,返回值类型为void
2
有return,返回值是什么类型, 则方法的返回值就是什么类型
3
有返回值,可以拿到程序执行的结果
4
没有返回值,程序运行完,结果就消失了
上一篇:怎么解一元二次方程?
下一篇:如何进行origin的曲线拟合