fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String s1 = "transaction";
  13. System.out.println(firstUniqueChar(s1));
  14.  
  15. String s2 = "reverse";
  16. System.out.println(firstUniqueChar(s2));
  17. }
  18.  
  19. public static char firstUniqueChar(String s) {
  20. char temp;
  21. for (int i = 0; i < s.length(); i++) {
  22. temp = s.charAt(i);
  23. if (countChars(s, temp) == 1) {
  24. return temp;
  25. }
  26. }
  27. return ' ';
  28. }
  29.  
  30. public static int countChars(String s, char c) {
  31. char[] chars = s.toCharArray();
  32. int result = 0;
  33. for (int i = 0; i < chars.length; i++) {
  34. if (chars[i] == c) {
  35. result++;
  36. }
  37. }
  38. return result;
  39. }
  40. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
r
v