To count characters of Multiple String > Java Program

To count characters of Multiple String > Java Program

Computer Networks


import java.io.*;
import java.util.*;
class CharacterCount {

   public static void main(String[] args)throws IOException {
      String s[];
      int x;
      InputStreamReader isr = new InputStreamReader(System.in);
      BufferedReader br = new BufferedReader(isr);
      System.out.print("ENTER NUMBER OF STRINGS: ");
      x = Integer.parseInt(br.readLine());
      s= new String[x];
      for(int i=0;i<x;i++){
      System.out.print("ENTER A STRING: ");
      s[i] = br.readLine();
      }
      for(int i=0;i<x;i++){
        System.out.print(s[i].length()+s[i]+"  "); 
      }
   }
   
}

/*
OUTPUT:
run:
ENTER NUMBER OF STRINGS: 2
ENTER A STRING: APPLE
ENTER A STRING: PINEAPPLE
5APPLE  9PINEAPPLE  BUILD SUCCESSFUL (total time: 18 seconds)
*/

Comments

Popular posts from this blog

Intermediate Code Generation > C Program