☕ Java Create Java hollow box with custom corners

Status
Not open for further replies.

IkaMusume

Forum Guru
Hello po gusto ko lang sana itanong kung paano palitan ang mga corners ng hollow box using for loop sa java

Java:
import java.util.Scanner;
public class Pattern1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter row and col");
        int row = sc.nextInt();
        int col = sc.nextInt();
        for (int i = 1; i <=row; i++) {
            for (int j = 1; j <= col; j++)
                if((i==1 || i==col) || (j==1 || j==col))
                    System.out.print("*");
                else
                    System.out.print(" ");
           
            System.out.println();
           
        }
    }
}

Output
Screenshot_2022-10-25-21-19-51-114-edit_ru.iiec.jvdroid.webp

Expect Output:
Code:
@********@
*        *
*        *
*        *
*        *
*        *
*        *
*        *
*        *
@********@

Sana po may makatulong saken
 
Status
Not open for further replies.

About this Thread

  • 0
    Replies
  • 720
    Views
  • 1
    Participants
Last reply from:
IkaMusume

Trending Topics

Online now

Members online
1,039
Guests online
912
Total visitors
1,951

Forum statistics

Threads
2,274,911
Posts
28,959,286
Members
1,233,484
Latest member
asawakoo03
Back
Top