Eclipse 小bug——Scanner用户输入时光标定位不对
import java.util.Scanner;
public class BookTest {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
Book b1 = new Book("明朝那些事儿2", "当年明月", 24.8, "相当好看!");
String[] strings = new String[5];
System.out.println("请输入书名!");
strings[0] = reader.next();
System.out.println("请输入作者!");
strings[1] = reader.next();
System.out.println("请输入价格!");
strings[3] = reader.next();
System.out.println("请输入评价!");
strings[4] = reader.next();
Book b2 = new Book(strings);
b1.showInfo();
b2.showInfo();
}
}
public class Book {
String name;
String author;
double price;
String comment;
public Book (String n , String aut , double p , String com ) {
name = n;
author = aut;
price = p;
comment = com;
}
public Book (String str[] ) {
name = str[0];
author = str[1];
price = Double.valueOf(str[2]);
comment = str[3];
}
void showInfo() {
System.out.println("《" + name + "》是" + author + "写的");
System.out.println("读者对这本书的评价是:" + comment);
}
}
在运行一段很简单的接收用户端输入时,发现了eclipse的一个小bug。
一开始默认的就是从第一行输入!
当你输入是英文时,自动跳到下一行;
当你输入是中文时,在上一个英文或者其他字符行的下一行;
难受了很久。。。。后来才知道这是eclipse自带的bug(╭(╯^╰)╮)