Blogger

Delete comment from: Javarevisited

Rajasekhar said...

I think this one is better


package com.array.example;

public class FirstNonRepeat {

public static void main(String[] args) {
String s = "swiss";
pairSum(s);

}

private static void pairSum(String sd) {
char[] c = sd.toCharArray();
char[] c1;
boolean status = false;
int index = 0;
for (int i = 0; i < c.length; i++) {
for (int j = i + 1; j < c.length; j++) {
if (c[i] == c[j]) {
status = false;
break;
} else {
status = true;
index = i;
}
}
if (status == true) {
System.out.println(status + " " + index + " " + c[index]);
break;
}
}

}
}

May 25, 2018, 3:48:05 AM


Posted to 3 ways to Find First Non Repeated Character in a String - Java Programming Problem Example

Google apps
Main menu