java - Want to count characters from cmd argument array -


i'm quite new java. have studied code long time , can't find way declare args array in simple string can count _length();

i getting args array doing following in cmd: java sentence day die. output way want atm, but, how efficiently count args array characters? way of declaring every single args[0], args[1], etc doesn't feel right.

right code:

public class sentence {      public static void main(string[] args) {         string s = args[0];         string t = args[1];         string = args[2];         string r = args[3];         string l = args[4];         int sum = s.length()+t.length()+a.length()+r.length()+l.length();          system.out.print("you wrote: ");          (int j=0; j < args.length; j++){             system.out.print(" "+args[j]);         }          if (args.length > 0) {             system.out.println("\nnumber of words:\t"+args.length);             system.out.println("number of characters:\t"+sum);         }     } } 

args array. should iterate on :

int sum=0; (string s : args) {     sum+=s.length(); } 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -