⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scanner20.java

📁 JAVA编程思想第四版英文原版习题答案. pdf原版的
💻 JAVA
字号:
// strings/Scanner20.java
// TIJ4 Chapter Strings, Exercise 20, page 549
/* Create a class that contains int, long, float and double and String fields.
* Create a constructor for this class that takes a single String argument, and
* scans that string into the various fields. Add a toString(0 method and 
* demonstrate that your class works correctly.
*/
import java.util.*;

public class Scanner20 {
	int i;
	long L;
	float f;
	double d;
	String s;
	Scanner20(String s) {
		Scanner sc = new Scanner(s);
		i = sc.nextInt();
		L = sc.nextLong();
		f = sc.nextFloat();
		d = sc.nextDouble();
		this.s = sc.next(); 		
	}
	public String toString() {
		return i + " " + L + " " + f + " " + d + " " + s;
	}
	public static void main(String[] args) {
		Scanner20 s20 = new Scanner20("17 56789 2.7 3.61412 hello");
		System.out.println(s20);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -