Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- import java.util.ArrayList;
- public class CharacterSorter {
- public static ArrayList<Character> characterList = new ArrayList<Character>();
- public static void main(String[] args){
- System.out.println("Welcome to Character Sorter Program");
- System.out.println("Please input a string to be sorted");
- Scanner scanner = new Scanner(System.in);
- String character = scanner.nextLine();
- boolean exit = false;
- while (!exit) {
- System.out.println("Please select the option you would like to see");
- System.out.println("");
- System.out.println("1. Display character frequencies alphabetically");
- System.out.println("2. Display sorted frequencies");
- System.out.println("3. Show types of character frequencies");
- System.out.println("4. Exit");
- int select = scanner.nextInt();
- if (select > 4 && select < 0){
- System.out.println("Error, bad input, please enter a number 1-4");
- }
- if (select == 1){
- alphabeticalSort();
- }
- if (select == 2){
- frequencySort();
- }
- if (select == 3){
- charTypes();
- }
- if (select == 4){
- System.out.println("Character Sorter Exited Successfully");
- exit = true;
- }
- }
- }
- public static void alphabeticalSort(String string) {
- for(Character c: string.toCharArray()){
- characterList.add(c);
- }
- Collections.sort(characterList);
- characterList.forEach(c->System.out.print(c));
- }
- // characterList.add(character);
- public static void frequencySort(){
- }
- public static void charTypes(){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement