Java基礎教程——使用Eclipse快速編寫Java輸入輸出代碼


Eclipse安裝

IDE:Integrated Development Environment,集成開發環境。好比是全自動洗衣機。

此處使用【eclipse-jee-4.6-neon-3-win32-x86_64】

下載鏈接:https://pan.baidu.com/s/1cWaMEneT4F2JDPOxu1tSAw

打開Eclipse

建工程:

File → New → Java Project

(如果找不到Java Project,就點擊Project…,彈出窗口中第一項就是Java Project)

建類:

src文件夾上右鍵→New→Class

輸入輸出和快速代碼

快速代碼:

// 快速生成main方法
// 打“main”按Alt+?組合件,點擊Enter
public static void main(String[] args){
}
// 快速生成輸出用的代碼
// 打“syso”按Alt+?組合件,點擊Enter
System.out.println();
// 自動生成返回值:
// 光標放到_sc.nextLine()上,鍵盤按下ctrl+1 -> 選擇“.... new local variable”(新本地變量)
String _s = _sc.nextLine();

參考:【Eclipse導入包】https://www.cnblogs.com/tigerlion/p/10663156.html


完整代碼:

import java.util.Scanner;

public class Test {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String nextLine = sc.nextLine();
		System.out.println("您輸入的是:" + nextLine);
		sc.close();
	}
}

next()和nextLine():

import java.util.Scanner;
public class TestScanner {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 輸入:aaa bbb ccc
		String str1 = sc.next();// 遇到空格、tab鍵就算讀取完畢
		System.out.println(str1);
		//---------------------------
		String str2 = sc.nextLine();// 讀取一行
		System.out.println(str2);
		sc.close();
	}
}

藍橋杯比賽中經常需要一行輸入多個數據,可以使用next()方法。
更詳細的解釋,后面會講到。鏈接:https://www.cnblogs.com/tigerlion/p/11179185.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM