title: Counting characters in a Character array - JAVA
body: <p>First off i am pretty fresh when it comes to java. My program is supposed to ask the user for strings and print what they just put in. It is then supposed to change all characters to lowercase and remove all spaces from the strings and print this. After this, it is supposed to print a character array of the alphabet and use an asterisk (*) to show each time a character occurs in the string (I dont even know where to start here). Right now it just prints the String in an array(not correct). This is what I have so far. It will print either the string with no spaces or the original but not both. My object/array naming is atrocious and i apologize in advance. Any guidance would be greatly appreciated  </p>
  
  <p>EDIT: here is the question
  In this assignment you are to write a program that will do the following:</p>
  
  <ol>
  <li><p>Ask the user to input a positive integer m, and then read that integer. Use a
  Scanner object declared in main to read this integer.</p></li>
  <li><p>Call a method that will ask the user to input m strings. As the strings are
  read, they should be concatenated into a single string st. After reading the m strings and forming the single string st, the method should return st. NOTE: This method will have two parameters, an int to receive m and a Scanner object to receive the Scanner object declared in main.</p></li>
  <li><p>In main print the concatenated string received from the method.</p></li>
  <li><p>In main convert the String object to lower case.</p></li>
  <li><p>In main convert the lower case String object to an array of char. (All letters
  will be lower case.)</p></li>
  <li><p>In main print the character array just created. (Requires a looping structure.)</p></li>
  <li><p>Call a method that will compress the character array in the following way.
  The method will count the letters of the alphabet in the array, create a new array whose size is equal to that count, and copy only the letters of the original array into the new array. Return the new array.</p></li>
  <li><p>In main declare an integer array of size 26. Call a method with two parameters, a character array x (which will contain only lower case letters, and an integer array z that will receive the one declared in main). The method will set all entries in the integer array to zero. It will then process through the lower case letter array and count the number of times each letter occurs. HINT: z[x[i]-97]++ can do the counting. The ASCII code for a is 97, so if x[i] is ‘a’, then z[0] will be incremented. ‘b’ would cause z[1] to be incremented, etc. The integer array now contains a frequency distribution for the letters in the array of lowercase letters.</p></li>
  <li><p>Call a method with one integer array parameter (which will receive the frequency distribution array) and print each letter on a new line followed by the number of stars equal to the integer value in that array element. This must be neatly aligned. Hint: if i is an index with 0 ≤  ≤ 25, then (char)(i+97) is a lower case letter of the alphabet.</p>
  
  <pre><code>package lab6;
  
  import java.util.Scanner;
  
  public class Lab6 {
  
      public char sent[];
  
  
  public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
  System.out.println("enter the number of strings you want: ");
  int m = input.nextInt();
  Lab6 loo = new Lab6();
  loo.print(loo.loop(m));
  
  
  }
  
  public String loop(int m) { //print the string that was entered
  String total = " ";
  for (int i = 1; i &lt;= m; i++) {
      Scanner input = new Scanner(System.in);
      System.out.println("enter string: " + i);
      String st = input.nextLine();
  
      total += st + "";
  
  }
  System.out.println(total);
  
  return total;
  
  }
  
  public void print(String ht) { //print array
  
  String st = ht.toLowerCase().replaceAll("\\s", "");
  sent = st.toCharArray();
  for (int i = 0; i &lt; sent.length; i++) {
      System.out.println(sent[i]);
  
          }
      }
  }
  </code></pre></li>
  </ol>