Last active
August 29, 2015 14:19
-
-
Save mariack/8812e6475b2f7057df15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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