7 Replies Latest reply: Aug 11, 2008 3:12 PM by 843785 RSS

    counting char with arrays Help

    843785
      here is my program but i am stuck on one part. what it does is you type in something name,word,anything it prints how many letters are in the name or word. i gave each array a value and used scanner to get user input all i have to do is tell the program to count. how do i do that??? thanks for any help


      import java.util.*;
      
      
      public class LettersInMyName {
      
         public static void main(String []args) {
           Scanner myScanner = new Scanner(System.in);
           char[] myArrayname;
           char myScan1, myScan2, myScan3, myScan4;
           myArrayname = new char[4];
      
             myScan1 = myScanner.findInLine(".").charAt(0);
             myScan2 = myScanner.findInLine(".").charAt(0);
             myScan3 = myScanner.findInLine(".").charAt(0);
             myScan4 = myScanner.findInLine(".").charAt(0);
      
             myArrayname[0] = myScan1;
             myArrayname[1] = myScan2;
             myArrayname[2] = myScan3;
             myArrayname[3] = myScan4;
      
      
      
             System.out.print(myArrayname[0]);
             System.out.print(myArrayname[1]);
             System.out.print(myArrayname[2]);
             System.out.print(myArrayname[3]);
             
      
      
      
      
      
           }
      
      }