英文:
Java substring exactly 3 letters from each word in the same string
问题
我有这个练习,我必须使用子字符串,并且从每个月中只显示前3个字母,如Jan,Feb等。我知道我必须使用months.substring(0,3)之类的东西,但我不知道如何用它来编写程序,你能指点我如何做吗?
String months[] = {"January ", "February ", "March ", "April ", "Mai ",
"June ", "July ", "August ", "September ", "October ", "November ", "December "};
for (String month : months) {
String abbreviatedMonth = month.substring(0, 3);
System.out.print(abbreviatedMonth);
}
英文:
I've got this exercise in which I have to use the substring and from each month to only display me the first 3 letters, Jan,Feb, etc. I know I have to use months.substring(0,3) or something like that but I don't know to do a program with that, can you point me on how to do it?
String months[] = {"January ", "February ", "March ", "April ", "Mai ",
"June ", "July ", "August ", "September ", "October ", "November ", "December "};
答案1
得分: 0
那就是你要寻找的内容
for(String month : months){
System.out.print(month.substring(0, 3) + " ");
}
英文:
That's what you are looking for
for(String month : months){
System.out.print(month.substring(0, 3) + " ");
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论