FirstNonRepeating

This commit is contained in:
2021-04-26 10:34:30 +05:30
parent 72b646f1ff
commit 688319db00
4 changed files with 52 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
// Program to find first non-repeating character in a string (Static Method).
public class FirstNonRepeatingStatic {
public static void main(String[] args) {
String str1 = "abcrabc";
System.out.println("The given string is: " + str1);
for (int i = 0; i < str1.length(); i++) {
boolean unique = true;
for (int j = 0; j < str1.length(); j++) {
if (i != j && str1.charAt(i) == str1.charAt(j)) {
unique = false;
break;
}
}
if (unique) {
System.out.println("The first non repeated character in String is: " + str1.charAt(i));
break;
}
}
}
}