What's new

Java Create Java hollow box with custom corners

Status
Not open for further replies.

IkaMusume

Forum Guru
Elite
Joined
Jan 27, 2018
Posts
1,008
Reaction
15,264
Points
1,879
Age
25
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.jpg

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

Sana po may makatulong saken
 

Attachments

Status
Not open for further replies.

Similar threads

Back
Top