java的方法(类似与C语言函数)
package www.nihao; import java.util.Scanner; public class demo02 { public static void main(String[] args) { //main方法 Scanner scanner = new Scanner(System.in); System.out.println("请输入X的值:"); int x=scanner.nextInt(); System.out.println("请输入Y的值:"); int y=scanner.nextInt(); int sum = add(x,y); System.out.println("调用方法后:"+"x="+x+"y="+y+"结果为:"+sum); scanner.close(); } public static int add (int a,int b) { return a+b; } }