Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. public class Ex17 {
  2.     public static void main(String[] args) {
  3.  
  4.         String word = "abcabcXyyzzf";
  5.  
  6.         char[] singleChar = new char[word.length()];
  7.         String[] checkArray = new String[word.length()];
  8.  
  9.         for (int i = 0; i < singleChar.length; i++) {
  10.             singleChar[i] = word.charAt(i);
  11.             for (int j = 0; j < singleChar.length; j++) {
  12.                 singleChar[j] = word.charAt(j);
  13.                 if (singleChar[i] == singleChar[j] && i != j) {
  14.                     checkArray[i] = "repeated";
  15.                 }
  16.             }
  17.  
  18.             if (checkArray[i] != "repeated") {
  19.                 System.out.println("First non-repeating character in word - " + word + " - is " + singleChar[i] + " at index: " + i);
  20.                 break;
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement