In general, I need to count the number of vowels in the n lines entered and sort them in ascending / descending order. To do this, I first translated String to Char, where I ran through all the letters and put a counter that counts the number of vowels. Next, Char put it back into the String and here I need to do the sorting, I can't figure out how to do it, tell me :)
import java.util.Scanner; public class projFour { public static void main(String[] args) { Scanner input = new Scanner(System.in); int row_val = 0, g = 1, localvar = 0; String temp; System.out.print("Enter row value: "); if(input.hasNextInt()){ row_val = input.nextInt(); } String[] a = new String[row_val + 1]; String[] c = new String[row_val + 1]; System.out.println("Enter " + row_val + " lines"); for (int i = 0; i < row_val + 1; i++){ if (input.hasNextLine()){ a[i] = input.nextLine(); } } char[] vowels = {'a','o','i','y','u','e'}; for (int i = 1; i < row_val + 1; i++) { char[] chars = a[i].toCharArray(); int k = 0; for (int j = 0; j < chars.length; j++){ for (int x = 0; x < vowels.length; x++) { if (chars[j] == vowels[x]) { k++; } } } //System.out.println("Odd val = " + k); String b = new String(chars); c[g] = b; System.out.println("String ========= " + c[g]); if (localvar > k) { temp = c[g - 1]; c[g - 1] = c[g]; c[g] = temp; localvar = k; } else { localvar = k; } g++; } for (int i = 1; i < row_val + 1; i++) { System.out.println("Sorted = " + c[i]); } } }