Thursday, 25 May 2023

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string

import java.util.*;

public class CountChars

{

    public static void main(String args[])

    {

        Scanner in=new Scanner(System.in);

        String s; int i;

        System.out.println("Enter a String");

        s=in.nextLine();

        for(i=0;i<s.length();i++)

           if(s.charAt(i)=='\0')

              break;

        System.out.println("The String "+s+" has "+i+" characters");

    }

}

No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...