Skip to content

Commit 70a66fd

Browse files
authored
Create NCR.java
1 parent 9fd3485 commit 70a66fd

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

NCR.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

0 commit comments

Comments
 (0)