Return to Snippet

Revision: 55757
at February 21, 2012 13:46 by nickstanish


Updated Code
for(i = 0; i < lastName.length; i++){
       chars[i] = (firstName[i] + lastName[i]).length();
       chars[i] = 17 - chars[i];
//use larger number if strings are bigger
       spaces[i] = "";
       while (chars[i]>0){
           chars[i]--;
           spaces[i] += " ";
       }
newArray[i] = lastName[i] + ", " + firstName[i] + spaces;
/*
* Nick Stanish
* newArray[i] is the formatted column, if the arrays are confusing
* then replace with a single string for easer readability
*/
}
//display
System.out.println(newArray[0] + "other string");

Revision: 55756
at February 21, 2012 13:44 by nickstanish


Initial Code
for(i = 0; i < lastName.length; i++){
       chars[i] = (firstName[i] + lastName[i]).length();
       chars[i] = 17 - chars[i];
       spaces[i] = "";
       while (chars[i]>0){
           chars[i]--;
           spaces[i] += " ";
       }
newArray[i] = lastName[i] + ", " + firstName[i] + spaces;
/*
* Nick Stanish
* newArray[i] is the formatted column, if the arrays are confusing
* then replace with a single string for easer readability
*/
}
//display
System.out.println(newArray[0] + "other string");

Initial URL
javafilter.heliohost.org

Initial Description
this is a snippet from a parsing piece of code I had to do for class, basically I had to grab employee names, numbers, paycodes, hours worked, etc. and organize it. In order to align the columns I ended up using some code like this

Initial Title
Format String for even columns

Initial Tags
format

Initial Language
Java