Write a program to find length of the String
import java.util.Scanner; public class StringLength { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Please Enter your String:-"); String str=sc.nextLine(); char c[]=new char[10]; c= str.toCharArray(); int count=0; try{ for( count=0;c[count] !='\0'; count++); } catch (ArrayIndexOutOfBoundsException e) { System.out.println(count); } } } OUTPUT:- Please Enter your String:- javainchennai The Length of the Given String is: 13
No comments:
Post a Comment