Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
hackerss
hackerss

Posted on

Java Contar cuantos caracteres tiene un string


import java.io.*;

public class CountCharacters {
   /**
   * This method count the characters of a string.
   * @param stringToCount the string to count.
   * @return int Obtains the number of characters of the string.
   */   
   public int countCharacters(String stringToCount) {
       //Variable to store the total sum
       int total = 0;
       //Sum the two numbers
       total = stringToCount.length();
       //Return the total
       return total;
   }

   /**
   * One Example
   */
   public static void main(String args[]) throws IOException {

      CountCharacters  countCharacters= new CountCharacters ();
      //Example
      int sum = countCharacters.countCharacters("Hola");
      //Output
      System.out.println("Sum of 10 and 20 is :" + sum); //30
   }
}
Enter fullscreen mode Exit fullscreen mode

Latest comments (0)