lunes, 1 de diciembre de 2014

Ejercicio 46

Autor: Miguel Ángel Romero
  package ejer46;
import java.util.Scanner;
/**
*
* @author juan
*/
public class Ejer46 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner leer = new Scanner(System.in);
        int num;

        do {
            System.out.println("Introduzca un número por teclado entre 3 y 10:");
            num = leer.nextInt();

        } while (num < 3 || num > 15 || num % 2 == 0);

        for (int i = 1; i < num; i = i + 2) {

            for (int k = i; k < num; k = k + 2) {
                System.out.print(" ");
            }
            for (int j = 0; j < i; j++) {
               
                if (j == 0 || j == i - 1) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }


            }
            System.out.println("");
        }

        for (int i = num; i >= 0; i = i - 2) {

            for (int k = num; k > i; k = k - 2) {
                System.out.print(" ");
            }
            for (int j = 0; j < i; j++) {
               
                if (j == 0 || j == i - 1) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }
            }
            System.out.println("");
        }
    }
   
}