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, }
3 Respostas
+ 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 :)
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)
0
But for that, the array and the input(in string) has to be sorted. The program will be very lengthy.