This Java code prints out the non-repeated characters in a given string. It works by iterating through the string character by character and comparing each character to all other characters in the string. If a character is found to be repeated, it is skipped. Otherwise, it is printed as a non-repeated character. Here is a breakdown of how the code works:
class Non_Repeating { public static void main(String[] args) { String str = "Java"; System.out.println("Given String : " + str); System.out.println("Non Repeated Character in String is :" ); for (int i = 0; i < str.length(); i++) { boolean u = true; for (int j = 0; j < str.length(); j++) { if (i != j && str.charAt(i) == str.charAt(j)) { u = false; break; } } if (u) { System.out.println(str.charAt(i)); } } } }
Given String : Java Non Repeated Character in String is : J v
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions