java之从命令行获取数据的三种方式
第一种:利用Scanner对象
import java.util.Scanner; public class TestInputOuput { public static void main(String[] args) { System.out.println("请输入:"); Scanner inp = new Scanner(System.in); String str = inp.next(); System.out.println("你输入了:"+str); } }
第二种:利用缓存流和输入流
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class TestInputOuput { public static void main(String[] args) throws IOException { System.out.println("请输入:"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("你输入了:"+br.readLine()); } }
第三种:利用输入框
import javax.swing.JOptionPane; public class TestInputOuput { public static void main(String[] args) { String jop = JOptionPane.showInputDialog(null,"请输入: ","输入框标题",JOptionPane.QUESTION_MESSAGE); System.out.println("你输入了:"+jop); } }
运行之后会弹出一个输入框,在中输入即可。
相关推荐
吹云 2020-11-05
84407805 2020-11-01
曾是土木人 2020-10-31
87201442 2020-10-15
java0 2020-09-29
81437716 2020-09-18
81437716 2020-09-13
bluecarrot 2020-09-11
myCat 2020-09-09
83427718 2020-09-07
85560694 2020-09-03
89520991 2020-08-21
89550191 2020-08-09
katie000 2020-08-04
hunningtu 2020-07-30
89961330 2020-07-28
yuzhongdelei0 2020-07-28
yuzhongdelei0 2020-07-27