Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ordenarNomes{
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String [] nomes = new String [20];
- for(int i=0;i<nomes.length;i++){
- System.out.println("Informe os nomes: ");
- nomes[i] = in.next();
- }
- String x = " ";
- for(int i=1;i<nomes.length-1;i++){
- for(int j=i+1;j<nomes.length;j++){
- if(nomes[i] > nomes[j]){
- x = nomes[i];
- nomes[i] = nomes[j];
- nomes[j] = x;
- }
- }
- }
- for(int i=0;i<nomes.length;i++){
- System.out.print(nomes[i]+" ");
- }
- }
- }
- import java.util.Scanner;
- class OrdenarNomes {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String[] nomes = new String[20];
- for (int i = 0; i < nomes.length; i++) {
- System.out.println("Informe os nomes: ");
- nomes[i] = in.next();
- }
- String x = " ";
- for (int i = 0; i < nomes.length - 1; i++) {
- for (int j = i + 1; j < nomes.length; j++) {
- if (nomes[i].compareTo(nomes[j]) > 0) {
- x = nomes[i];
- nomes[i] = nomes[j];
- nomes[j] = x;
- }
- }
- }
- for (int i = 0; i < nomes.length; i++) System.out.print(nomes[i]+" ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement