Pergunta de entrevista da empresa EY

Given a string "abcdaghj". Process this char by char and print a msg "already processed" when its not the first time you find this char.

Respostas da entrevista

Sigiloso

17 de ago. de 2019

public static void main(String[] args) { String s = "abcdaghj"; char cList[] = s.toCharArray(); boolean isProcessed; for (int i = 0; i < cList.length; i++) { isProcessed = false; for (int j = i; j < cList.length; j++) { if (cList[i] == cList[j] && i != s.indexOf(cList[j])) { isProcessed = true; System.out.println( "Already processed " + cList[i] + " index :" + i + " first index :" + s.indexOf(cList[j])); } } if (!isProcessed) { System.out.println("Processing " + cList[i] + " first index :" + s.indexOf(cList[i])); } } }

3

Sigiloso

14 de mai. de 2016

I was able to write correct program.

5