-4
我正在编写我的第一个java程序,我终于得到了它所有的书面,但在赋值我需要添加一个函数(主除外)。我的程序计算了名字中的字母数量,所以我想也许我可以添加一个读取多少字母大写的函数?有任何想法吗?将函数添加到java程序
public class NameLetters{
public static void main(String []args){
Scanner in = new Scanner(System.in);
String firstName; //Asks for the users first name
int count=0; //Count the letters passing through loop
System.out.print("Hello, this program will ask for your first name and then output the number of letters in your name.");
System.out.print("Please enter your first name:");
String firstName = input.NextLine();
for (int i=0; i<firstName.length(); i++) {
if (firstName.charAt(i) != ' ')
Count ++;
}
system.out.print("There are "+Count+" s in the first name "+firstName+" , Thank you for participating. Goodbye!");
}
}
是,读的教程,例如http://www.learnjavaonline.org/en/Functions –
使用['Character.isUpperCase()'](https://docs.oracle.com/javase/8/docs/api/java/lang/Character.html #isUpperCase-煤焦)。 – Boann