File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+ class NCR
3+ {
4+ public static void main (String [] args )
5+ {
6+ Scanner s = new Scanner (System .in );
7+ System .out .println ("Enter number of times" );
8+ int times = Integer .parseInt (s .nextLine ());
9+ for (int i =0 ;i <times ;i ++){
10+ System .out .println ("enter length" );
11+ int l = Integer .parseInt (s .nextLine ());
12+ System .out .println ("enter string" );
13+ String str = s .nextLine ();
14+ int a =0 ;
15+ int b =0 ;
16+ boolean chance =true ;
17+ StringBuffer sb = new StringBuffer (str );
18+
19+ while (sb .length ()>0 )
20+ {
21+
22+ char c = sb .charAt (0 );
23+ if (c =='a' ||c =='e' ||c =='i' ||c =='o' ||c =='u' )
24+ {
25+ sb .replace (0 ,1 ,"z" );
26+
27+ }
28+ else
29+ {
30+ sb .deleteCharAt (0 );
31+ }
32+ if (chance )
33+ a ++;
34+ else
35+ b ++;
36+ chance = !chance ;
37+ }
38+ if (a >b )
39+ System .out .println ("A" );
40+ else if (b >a )
41+ System .out .println ("B" );
42+ else
43+ System .out .println ("D" );
44+ }
45+
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments