Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package numerosordemcrescente;
  2.  
  3. /**
  4.  *
  5.  * @author Vini
  6.  */
  7. public class Main {
  8.  
  9.     /**
  10.      * @param args the command line arguments
  11.      */
  12.     public static void main(String[] args) {
  13.  
  14.         int numerosOrdemCrescente = 0;
  15.  
  16.         for (int i = 1000; i <= 9999; i++) {
  17.             int primeiroDigito = i/1000;
  18.             int segundoDigito = (i%1000)/100;
  19.             int terceiroDigito = (i%100)/10;
  20.             int quartoDigito = i%10;
  21.  
  22.             if (primeiroDigito < segundoDigito && segundoDigito < terceiroDigito && terceiroDigito < quartoDigito) {
  23.                 System.out.println(i);
  24.                 numerosOrdemCrescente += 1;
  25.             }
  26.         }
  27.  
  28.         System.out.println("\nNúmeros em ordem crescente entre 1000 e 9999: " + numerosOrdemCrescente);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement