0

Write a program in java to print each character of a string without repeating any.

Example 1 :- Input : LONDON Output : { L, O, N, D, } Example 2 :- Input : PHOTOPHOSPHORYLATION Output :- { P, H, O, T, S, R, Y, L, A, I, N, }

23rd Jan 2017, 4:14 PM
Advik Singhania
Advik Singhania - avatar
3 odpowiedzi
+ 1
It will be lengthy, I am no Java expert and there is probably someone that is better than me, I was just giving you an idea of how you could do it. Maybe research will do you good :)
23rd Jan 2017, 6:08 PM
Dawzy
Dawzy - avatar
0
I am no Java expert and I have never coded in Java but I have heard that Java is similar to C++(Might be wrong, might be right I dunno) The way I would approach this by making an array, and then a for loop that checks each letter with the elements of the array, if letter matched an element in the array then it will not print else it will print and add it to the array. Know what I mean? Edit: I just did it in Python(ik there is no point, but I just wanted to share) #For all of you Python experts userInput = input() checkList = [] result = "" for letter in userInput: if not letter in checkList: checkList.append(letter) result += letter print(result)
23rd Jan 2017, 4:58 PM
Dawzy
Dawzy - avatar
0
But for that, the array and the input(in string) has to be sorted. The program will be very lengthy.
23rd Jan 2017, 4:59 PM
Advik Singhania
Advik Singhania - avatar