Advertisement
cesarnascimento

formatação de textos com array aula 45

May 25th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1.  
  2. public class exript {
  3.  
  4.     public static void main(String[] args) {
  5.         int[] array; // declaraçao do array
  6.         array = new int[10]; // cria e reserva espaço p array
  7.         // vai do 0... 9 > 10 elementos
  8.         System.out.printf("%s%10s\n", " _______", " ________ ");
  9.         System.out.printf("%s%10s\n", "|Indice ", "| Valores|");
  10.         System.out.printf("%s%10s\n", "|-------", "|--------|");
  11.         for( int i = 0; i <= 9; i++){
  12.             System.out.printf("|%5d%3s%7d |\n",i, " |",array[i]); // 5 casas %5d e 7 casas %7d
  13.         }
  14.         System.out.printf("%s%10s\n", "|-------", "|--------|");
  15.  
  16.     }
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement