Java Program to display the length of the elements in an array containing string values to another array.

PROGRAM:

public class Solution {                                                                                                           

public static void main(String[] args) throws Exception {                                            

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));   

   String[] s= new String[10];                                                                                                      for(int i=0;i<s.length;i++)                                                                                                   

{

s[i]=br.readLine();

   }

int[] n=new int[10];                                                   

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

n[i]=s[i].length();                                                 
System.out.println(n[i]);

}

}}

INPUT:

 grandfather

grandmother

father

mother

son

daughter

cat

dog

program

car          

OUTPUT:

11

11

6

6

3

8

3

3

7

3                                   

                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 

Comments

Popular posts from this blog

Python program to sum up the Salary when the Name and Age matches with subsequent rows.

Automation using selenium and python/java interview question to order a product in e commerce website.