如何在java语言中传递来自用户的参数。
例如:
我将该方法称为enQueue(Object o)
我希望用户为o输入一个值
我在测试课上试过了
Object o = read.nextLine();
q.enQueue(o);它只调用该方法,而不传递任何参数
发布于 2011-05-15 23:09:23
这可能是因为read.nextLine()不返回任何内容(null)或返回空字符串""。
通过使用调试器或打印来确保返回值是什么:
Object o = read.nextLine();
System.out.println("I got: " + o);此外,如果您只在队列中使用java.lang.String的实例,我建议您使用泛型:
Queue<String> q = new LinkedList<String>();
String s = read.nextLine();
q.enQueue(s);https://stackoverflow.com/questions/6009214
复制相似问题