Java program to find no of words when each no starts with uppercase except 1st one
import java.util.Scanner;
public class Strring {
public static void main(String args[])
{
String s;
char c;
int count =0;
Scanner br = new Scanner(System.in); //use for input//
System.out.println("enter string");
s=br.nextLine();
for(int i=0;i<s.length();i++)
{
c=s.charAt(i);
if(s.charAt(0)>='A'&&s.charAt(0)<='Z')
{
System.out.println("Start with small letters please..!!");
return;
}
else if(c>='A'&&c<='Z')
{
count++;
}
}
System.out.println(" no of words="+(count+1));
}
}
No comments:
Post a Comment