jeudi 26 novembre 2020

how can i draw a specific pattern is java

how can I draw :

******
******
**  **
**  **
**  **
**  **
**  **
**  **
******
******

What is the logic behind it, or if I want to draw something else such as an alphabet or a number the code I used under will draw a rectangle filled with stars. How can I use loops and if statements to make spaces in between the stars I showed above?

import java.util.Scanner;

public class rectangle {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        System.out.println("Enter size:");
        int size = sc.nextInt();
        
        System.out.println("Enter ShapeS:");
        String shape  = sc.next();
        for (int i = 1; i<=5*size; i++) {
            for (int j = 1; j<=3*size; j++) {
                System.out.print(shape);
            }
            System.out.println();
        }

Aucun commentaire:

Enregistrer un commentaire