package com.fqs.test; import java.util.Arrays; import java.util.Random; public class hello { public static void main(String[] args) { //调用方法 playGame(); playGame(); } //main方法外面写一个方法玩游戏 public static void playGame(){ System.out.println("玩游戏"); System.out.println("输掉游戏"); } }
求和
package com.fqs.test; public class hello { public static void main(String[] args) { //定义一个方法,在方法的内部定义两个变量,求出他们的和并进行打印 getSum(); } public static void getSum(){ int a=1; int b=2; int sum=0; sum=a+b; System.out.println("sum:"+sum); } }
求和传参
package com.fqs.test; public class hello { public static void main(String[] args) { //定义一个方法,在方法的内部定义两个变量,求出他们的和并进行打印 getSum(1,2); getSum(11,22); } public static void getSum(int a,int b){ int sum=0; sum=a+b; System.out.println("sum:"+sum); } }
标签:求和,sum,int,getSum,64,void,static,方法,public From: https://www.cnblogs.com/haha1988/p/17462972.html