Java从同一个字符串的每个单词中精确地提取3个字母substring。

huangapple go评论83阅读模式
英文:

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) + " ");
}

huangapple
  • 本文由 发表于 2020年10月17日 17:04:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/64400764.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定