jeudi 9 janvier 2020

How to get out an array in if statement? Help me

here some java code here but ı couldn't fix the problem. ı don't understand how to get out the picture array in if statement.How do ı take out the array ı have defined in the if? in option 1, ı ask height and width then ı write for loop and the output will consist of zero but ı can't take this picture , when ı come the option 2 picture can not be found. and for option 3 ı want to keep the color but ı can not write the code. please help me and sorry for my bad english...


public class project3 {
    public static void main(String[] args) {
        System.out.println("Hello, Welcome to Işık Photoshop program.");
        while (true) {
            Scanner input = new Scanner(System.in);
            System.out.println("The following options are available for you:");
            System.out.println("1) Create a picture");
            System.out.println("2) Clear the picture");
            System.out.println("3) Color pixel (X, Y) in color C");
            System.out.println("4) Draw vertical segment");
            System.out.println("5) Draw horizontal segment");
            System.out.println("6) Draw filled rectangle in color C");
            System.out.println("7) Fills region with color C starting with pixel (X, Y)");
            System.out.println("8) Exit Program");
            System.out.print("Choose an option: ");
            int option = input.nextInt();

            int[][] picture = new int[0][];
            if (option == 1) {
                System.out.print("What is the height of picture?");
                int height = input.nextInt();
                int[] h = height;
                System.out.print("What is the width of picture?");
                int width = input.nextInt();
                picture = new int[height][width];
                for (int i = 0; i < picture.length; i++) {
                    for (int j = 0; j < picture[i].length; j++) {
                        System.out.print(picture[i][j]);
                    }
                    System.out.println();
                }>>>how to get out picture array in if statement?

            } else if (option == 2) {
                System.out.println(picture);>>>and this output like that [[I@2b193f2d. but it can't be like that.ı don't understand.help me.

            } else if (option == 3) {
                System.out.println("Enter X?");
                int x = input.nextInt();
                System.out.println("Enter Y?");
                int y = input.nextInt();
                System.out.println("Enter Color?");
                char color = input.next().charAt(0);
                char[] chars = new char[color];
                picture[x][y] = color;


            } else if (option == 4) {
                System.out.println("Enter Y?");
                int y = input.nextInt();
                System.out.println("Enter X1?");
                int x1 = input.nextInt();
                System.out.println("Enter X2?");
                int x2 = input.nextInt();
                System.out.println("Enter Color?");
                char color = input.next().charAt(0);
                for (int i = x1; i <= x2; i++) {
                    picture[y][i] = color;
                }


            } else if (option == 5) {
                System.out.println("Enter X?");
                int x = input.nextInt();
                System.out.println("Enter Y1?");
                int y1 = input.nextInt();
                System.out.println("Enter Y2?");
                int y2 = input.nextInt();
                System.out.println("Enter Color?");
                char color = input.next().charAt(0);
                for (int i = y1; i <= y2; i++) {
                    picture[i][x] = color;
                }

            } else if (option == 6) {
                System.out.println("Enter X1?");
                int x1 = input.nextInt();
                System.out.println("Enter Y1?");
                int y1 = input.nextInt();
                System.out.println("Enter X2?");
                int x2 = input.nextInt();
                System.out.println("Enter Y2?");
                int y2 = input.nextInt();
                System.out.println("Enter Color?");
                char color = input.next().charAt(0);
                for (int i = x1; i <= x2; i++) {
                    for (int j = y1; j < y2; j++) {
                        picture[j][i] = color;
                    }

                }

            } else if (option == 7) {
                System.out.println("Enter X?");
                int x = input.nextInt();
                System.out.println("Enter Y?");
                int y = input.nextInt();
                System.out.println("Enter Color?");
                char color = input.next().charAt(0);

            } else if (option == 8) {
                break;
            } else
                System.out.println("Wrong option!. Please rewrite option.");
        }

    }

}```

Aucun commentaire:

Enregistrer un commentaire