I am beginner in java, and I have this question :
**Q01 [ 7 marks] Write a java program that take string as input and using the method EvenPairs(str) to check whether there's even pair exists or not for each character (i.e. Alphabet). Sample Test Cases
Input:"3gy41d21y363"
Output:
- 3 – False
- g – false
- y – true
- 4 – false
- 1 – true
- d – false
as you seen in the output, each character occurrence printed only one time even if it is duplicated, I solved the problem until this step I can not find a solution to print the character only 1 time with the result if it is true or false
this is my code:
package evenpairornot;
import java.util.Scanner;
public class EvenPairOrNot {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
System.out.print("Enter a string: ");
String s1=input.nextLine();
EvenPairs(s1);
}
public static void EvenPairs(String s){
char [] chs=s.toCharArray();
int count=0;
for (int i = 0; i <chs.length; i++) {
for (int j = 0; j <chs.length; j++) {
if (chs[i]==chs[j]){
count++;
}
}
if(count%2==0)
System.out.println(s.charAt(i)+"- true");
else
System.out.println(s.charAt(i)+"- False");
count=0;
}
}
}
and this is the output:
Enter a string: 3gy41d21y363
3- False
g- False
y- true
4- False
1- true
d- False
2- False
1- true
y- true
3- False
6- False
3- False
waiting for your help!! thank you