Java program to print the length of all strings from a given array
KW.java
classKW{publicstaticvoidmain(Stringargs[]){System.out.println("———————————————————————————————————————————");System.out.println("Program to print strings and its length");System.out.println("———————————————————————————————————————————");Strings[]={"Mouse","Keyboard","Processor","Pen Drive","Joystick"};System.out.println("Array contains the following strings"+"\n{");for(Stringarr:s)System.out.println(" "+arr);System.out.println("}\n");for(inti=0;i<s.length;i++)System.out.println(s[i]+" "+s[i].length());System.out.println("———————————————————————————————————————————");}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
———————————————————————————————————————————
Program to print strings and its length
———————————————————————————————————————————
Array contains the following strings
{
Mouse
Keyboard
Processor
Pen Drive
Joystick
}
Mouse 5
Keyboard 8
Processor 9
Pen Drive 9
Joystick 8
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.