Created
August 28, 2016 02:28
-
-
Save washingtonsoares/77c781546bdd16e54b439a72d77237c4 to your computer and use it in GitHub Desktop.
Palavras ordenadas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String args[]){ | |
Scanner sc = new Scanner(System.in); | |
ArrayList<String> palavras = new ArrayList<>(); | |
int qtd = sc.nextInt(); | |
sc.nextLine(); | |
while(qtd > 0){ | |
String palavra = sc.nextLine(); | |
palavras.add(palavra); | |
qtd--; | |
} | |
for(String palavra : palavras){ | |
char[] letras = palavra.toLowerCase().toCharArray(); | |
char[] copyOfLetras = letras.clone(); | |
Arrays.sort(letras); | |
if(Arrays.equals(copyOfLetras, letras)){ | |
System.out.println(palavra + ": O"); | |
}else{ | |
System.out.println(palavra + ": N"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment