Advertisement
diloentutospc

cuadrado asteriscos solo bordes java

Nov 15th, 2018
22,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CuadradoBlanco {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         Scanner teclado = new Scanner(System.in);
  8.        
  9.         System.out.print("Por favor ingrese el tamaño del cuadrado: ");
  10.         int n = teclado.nextInt();
  11.        
  12.         if(n >= 0 && n<=50) {
  13.             //Linea superior
  14.             for(int i = 0; i < n; i++) {
  15.                 System.out.print("*");
  16.             }
  17.             System.out.println();
  18.            
  19.             //centro de la forma
  20.             for(int i = 0; i < n-2; i++) {
  21.                 System.out.print("*");
  22.                 for(int j = 0; j < n-2; j++) {
  23.                     System.out.print(" ");
  24.                 }
  25.                 System.out.println("*");
  26.             }
  27.            
  28.             //Linea inferior
  29.             for(int i = 0; i < n; i++) {
  30.                 System.out.print("*");
  31.             }
  32.         }else {
  33.             System.out.println("Error. El dato a ingresar de "
  34.                     + "estar entre 0 y 50");
  35.         }
  36.                
  37.  
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement