☕ 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
  • 751
    Views
  • 1
    Participants
Last reply from:
IkaMusume

Trending Topics

Online now

Members online
1,211
Guests online
8,555
Total visitors
9,766

Forum statistics

Threads
2,329,786
Posts
29,250,081
Members
1,154,624
Latest member
raeeee
Back
Top