Two Java assignments Involving creating shapes using a 2d array,

1 answer below »
Answered Same DayJan 24, 2021

Answer To: Two Java assignments Involving creating shapes using a 2d array,

Neha answered on Jan 25 2021
145 Votes
74881 - java code/cube.docx
import java.util.Scanner;
public class Cube {
    public static void main(String[
] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the size of the cube: ");
        int size = input.nextInt();
        
        char[][] cube = new char[3*size -2][2*size -1];
        
        for(int i=size-1, j=0; i>=0; i--, j++) {
            cube[i][j] = '*';
        }
        for(int i=0, j=(2*size-1)/2; i            cube[i][j] = '*';
        }
        for(int i=size; i<2*size-1; i++) {
            cube[i][0] = '*';
            cube[i][2*size-2] = '*';
        }
        for(int i=size-1, j=0; i<2*size-1; i++, j++) {
            cube[i][j] = '*';
            cube[i][2*size-1 -j-1] = '*';
        }
        
        for(int i=2*size-2, j=0; i<3*size-2; i++,j++ ) {
            cube[i][j] = '*';
            cube[i][2*size-1 -j-1] = '*';
        }
        for(int i=2*size-2; i<3*size-2; i++) {
            int j = (2*size-1)/2;
            cube[i][j] = '*';
        }
        //Print the cube
        for(int i=0; i            for(int j=0; j                System.out.print(cube[i][j]);
            }
            System.out.println();
        }
    }
}
74881 - java code/Cube.java
74881 - java...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here