Question:-
Steffi plans a game to teach her students about vowels . There are 5 students .Steffi places 25 slip of papers in a fishbowl, where each slip contains a word.Each student has to take 5 slips and count the number of vowels in each slip and write it in a paper consecutively.
The Points are given as below
No of Vowels | Points |
1 | 0 |
2 | 1 |
3 | 3 |
4 | 4 |
5 | 6 |
More than 5 | 8 |
A student who gets the highest point is considered the winner. When no point is scored by anyone then display “No one has got any points”.
Sample input 1
mango basket ball auspicious kangaroo
precaution misbehavior battery cup screen
parasite hello good come education
invitation squeeze paper ant multiplication
COOPERATION DEMOCRACY CONGRATULATIONS YOU BYE
Sample output 1
1 1 0 8 4
6 6 1 0 1
4 1 1 1 6
6 4 1 0 8
8 3 8 1 0
1 14
2 14
3 13
4 19
5 20
The winner is student 5 with points 20
Code:-
Main.java
import java.util.*; public class Main { public static void main (String[] args) { char vowels[]={'A', 'E', 'I', 'O', 'U'}; //String vowels[]={"A", "E", "I", "O", "U"}; String input[][]=new String[5][5]; Scanner sc=new Scanner(System.in); String ip[]=new String[5]; for(int i=0; i<5;i++) { ip[i]=sc.nextLine(); input[i]=ip[i].split(" "); } int vowel_count[][]=new int[5][5]; int count=0; for(int i=0;i<5;i++) { for(int j=0 ; j<5;j++) { for(int k=0; k<5;k++) { char temp=vowels[k]; for(int l=0; l<input[i][j].length(); l++) { if(temp==Character.toLowerCase(input[i][j].charAt(l)) || temp==Character.toUpperCase(input[i][j].charAt(l))) { count++; } } } vowel_count[i][j]=count; count=0; } } int score[] =new int[5]; for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { if(vowel_count[i][j]==1 || vowel_count[i][j]==0) { System.out.print("0\t"); score[i]+=0; } else if(vowel_count[i][j]==2) { System.out.print("1\t"); score[i]+=1; } else if(vowel_count[i][j]==3) { System.out.print("3\t"); score[i]+=3; } else if(vowel_count[i][j]==4) { System.out.print("4\t"); score[i]+=4; } else if(vowel_count[i][j]==5) { System.out.print("6\t"); score[i]+=6; } else { System.out.print("8\t"); score[i]+=8; } } System.out.println(); } int max=0; String max_index=new String(); for(int i=0;i<5;i++) { System.out.println((i+1)+"\t"+score[i]); if(score[i]>max && score[i]!=0) { max=score[i]; max_index=max_index+"student "+String.valueOf(i+1)+" "; } else if(score[i]==max && score[i]!=0) { max_index=max_index+"student "+String.valueOf(i+1)+" "; } } if(max!=0) { System.out.println("The winner is "+max_index+"with points "+max); } else { System.out.println("No one has got any points"); } } }
Recommended:-
- Array square
- Generate number using odd digits
- Alternate Number Difference
- Next Greatest number
- Mark Comparison
- Print the characters in descending order
- Vowels in a fishBowl
- Least offer
- Ascending and descending order
- Mail Domain
- Count repeating words
- Sentence – Convert to upper and lower
- Count consecutive repeating characters
- Zig zag Array
- Pass and Fail Count
- Search a Course
- Average and Grade Calculation
- String – Find and replace the character (first occurrence)
- Sort the first and second half of an array
- Retail Shop
- Palindrome
- Numerology
- InitCap
- Array Compatiblilty
- Sum of the maximum and the minimum element
- String Concatenation
- Find Average Age
- Login