类似于python里的input:
package day7; import java.util.Scanner; public class ScannerClass { String name; int age; public void infoInteraction(){//数据交互 System.out.println("==============in the infoInteraction============="); Scanner info = new Scanner(System.in); System.out.println("please input your name:"); name = info.next(); System.out.println("please input your age:"); age = info.nextInt(); } public Long sum(){//求和 System.out.println("================in the sum================"); Scanner count = new Scanner(System.in); System.out.println("please input a:"); Long a = count.nextLong(); System.out.println("please input b:"); Long b = count.nextLong(); System.out.println("please input c:"); Long c = count.nextLong(); System.out.println("the sum is :"+(a+b+c)); return a+b+c; } public Long max(){//求最大值 System.out.println("================in the max================"); Scanner num = new Scanner(System.in); System.out.println("please input a:"); Long a = num.nextLong(); System.out.println("please input b:"); Long b = num.nextLong(); System.out.println("please input c:"); Long c = num.nextLong(); Long max; max = a > b ? a : b; max = max > c ? max : c; System.out.println("the max is :"+max); return max; } } 另起一个类: package day7; public class Tes { public static void main(String[] args) { ScannerClass a = new ScannerClass(); a.infoInteraction(); System.out.println("your name is :"+a.name+","+"your age is :"+a.age); a.sum(); a.max(); } }