我是新来的java,所以很抱歉,如果这是一个明显的问题。如何阅读在字符串中的字符在java中
我试图按字符读取字符串来创建树节点。 例如,输入"HJIOADH"
和节点都H J I O A D H
我注意到,
char node = reader.next().charAt(0); I can get the first char H by this
char node = reader.next().charAt(1); I can get the second char J by this
我可以使用一个周期来获取所有的人物?像
for i to n
node = reader.next().charAt(i)
我试过了,但它不起作用。
我该怎么做?
非常感谢您的帮助。
Scanner reader = new Scanner(System.in); System.out.println(“输入您的节点为大写字母无空格,'/'结尾”); int i = 0; char node = reader.next()。charAt(i); 而(节点!=“/”){
CreateNode(node); // this is a function to create a tree node
i++;
node = reader.next().charAt(i);
}
安置自己的完整的代码,因为我们不知道读者? – brso05 2014-10-10 18:52:39
使用'char [] array =“HJIOADH”.toCharArray();获取数组中的字符''探索'String'类中存在的方法本身。 – Braj 2014-10-10 18:52:39
谢谢大家!我知道了。 – Ahaha 2014-10-10 19:10:24