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

Trending Topics

Online now

Members online
352
Guests online
1,639
Total visitors
1,991

Forum statistics

Threads
2,292,892
Posts
29,080,013
Members
1,209,573
Latest member
noaf
Back
Top