Skip to content

Instantly share code, notes, and snippets.

@mariack
Last active August 29, 2015 14:19
Show Gist options
  • Save mariack/8812e6475b2f7057df15 to your computer and use it in GitHub Desktop.
Save mariack/8812e6475b2f7057df15 to your computer and use it in GitHub Desktop.
/**
* Maria Kalusz
* Lab 12 - Array of Counters
* April 24, 2015
*/
package assignments;
import java.util.Arrays;
import java.util.Scanner;
public class ArrayCounter
{
public static void main(String[] args)
{
Scanner keyboard;
String[] arr;
String input;
int i, j, len, count;
System.out.print("Enter something: ");
keyboard = new Scanner(System.in);
input = keyboard.nextLine().toLowerCase().replaceAll("\\W", "");
len = input.length() + 1;
arr = input.split("", len);
Arrays.sort(arr);
count = 0;
for(i = 1; i < len; i++)
{
System.out.print(arr[i] + " ");
for(j = 1; j < len; j++)
{
if (arr[i].equals(arr[j]))
{
count++;
System.out.print(count);
}
else
{
count = 0;
}
}
System.out.println();
}
while(input.length() != 0)
{
System.out.print("Enter something:");
input = keyboard.nextLine().toLowerCase().replaceAll("\\W", "");
len = input.length() + 1;
arr = input.split("", len);
Arrays.sort(arr);
count = 0;
for(i = 1; i < len; i++)
{
System.out.print(arr[i] + " ");
for(j = 1; j < len; j++)
{
if (arr[i].equals(arr[j]))
{
count++;
System.out.print(count);
}
else
{
count = 0;
}
}
System.out.println();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment