Hello!

A task is given to search for vowels in strings of a set of char characters, to enter several lines of characters. It is necessary to determine the number of vowels in each line SEPARATELY.

For one line, everything works without problems (did through BufferedReader ), and how to do several?

  • And what's the problem? Enter a few lines? - post_zeew
  • yes, separately. - GenykS
  • See the answer. - post_zeew

2 answers 2

The entered strings will be stored in the array String[] strings .

First, enter the size of the array, then create this array and enter the lines themselves:

 int n; Scanner scanner = new Scanner(System.in); System.out.print("Введите количество строк: "); if (scanner.hasNextInt()) { n = scanner.nextInt(); } else { System.out.print("Введены некорректные данные!"); return; } String[] strings = new String[n]; for (int i=0; i<n; i++) { System.out.print("Введите строку номер " + (i+1) + ": "); strings[i] = scanner.next(); } 

As a result, we get an array of strings.

  • And how now to work with each line separately? - GenykS
  • @ GeorgiyStepuk, The first line is strings[0] , the second is strings[1] and so on. - post_zeew
  • Resolve in the following way, but now does not consider the last line - GenykS
 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String [] s = new String[16]; int i = 0; int j = 0; for (i=0; i<16; i++){ s [i] = reader.readLine(); char [] ch = s[i].toCharArray(); int count = 0; for (j=0; j<ch.length; j++){ if (ch[j]=='a'||ch[j]=='o'||ch[j]=='e'||ch[j]=='i'||ch[j]=='y'||ch[j]=='u'){ count++; } else continue; } System.out.println(count); }