Carlos Montoya
strings123
1 Answer(s)      5 years and 9 months ago
Posted in : Java Beginners

How can I count total chars out of an input string in java or in objective-c?

Ads

View Answers

January 4, 2011 at 10:49 AM


Hi Friend,

Try the following code:

import java.util.*;

class  CountCharacters {
  public static void main(String[] args) throws Exception{
  Scanner input=new Scanner(System.in);
  System.out.print("Please enter string ");
  String str=input.nextLine();
  String st=str.replaceAll(" ", "");
  char ch[]=st.toCharArray();
  int count=ch.length;
  System.out.println("Total Characters: "+count);
}
}

Thanks










Related Tutorials/Questions & Answers:
strings123
strings123  How can I count total chars out of an input string in java or in objective-c?   Hi Friend, Try the following code: import java.util.*; class CountCharacters { public static void main(String[] args

Ads

Advertisement