Java char数组添加和更改单词 [英] Java char array add and change words
本文介绍了Java char数组添加和更改单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
打印扫描单词的代码,希望程序打印出任何z替换为y的单词
公共类Char {
public static void main(String [] args){
System.out.println(请输入你的话);
扫描仪扫描=新扫描仪(System.in);
String word = scan.nextLine();
for(char a:word.toCharArray())
{
System.out.println(a);
}
}
}
我尝试了什么:
使用不同的参数多次更改代码
解决方案
Scanner类中有许多不同的nextXXX方法。选择最能为您的问题提供解决方案的解决方案:扫描程序(Java Platform SE 7) ) [ ^ ]。
code that prints the scanned word, would want the program to print word where any occurrence of z is replaced with y
public class Char { public static void main(String[] args) { System.out.println("Please enter your words"); Scanner scan = new Scanner(System.in); String word = scan.nextLine(); for(char a : word.toCharArray()) { System.out.println(a); } } }
What I have tried:
changed code several times with different arguments
解决方案
There are many different nextXXX methods in the Scanner class. Choose one that most closely provides a solution to your problem: Scanner (Java Platform SE 7 )[^].
这篇关于Java char数组添加和更改单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文