java中要從控制臺輸入數(shù)字的代碼怎么寫?
如果要int類型,只要把doubleinput=scanner.nextDouble();換為intinput=scanner.nextInt().同樣適用于float,shortbyte等類型importjava.util.Scanner;publicclassABC{publicstaticvoidmain(String[]args){doubleinput=getInputFromConsole();}//接受控制臺輸入數(shù)字privatestaticdoublegetInputFromConsole(){Scannerscanner=newScanner(System.in);doubleinput=scanner.nextDouble();returninput;}}
上一篇word怎么批量替換圖1
下一篇20毫秒對應頻率