Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Thursday, 28 July 2016

Count number of words java

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