Write a program to count number of Character in String
======================================================================
import java.util.Scanner;
class CountCharacter{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)!=' ')
count++;
}
System.out.println("Number Of Character:"+count);
}
}
class CountCharacter{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)!=' ')
count++;
}
System.out.println("Number Of Character:"+count);
}
}
Output
====================================================================
Comments
Post a Comment