Menu

[Solved]Java Need Help Figure Actually Homework Made 2d Array Local Method Worked Tried Make Attri Q37149968

Java. I need help to figure this out before I can actually do myhomework. When I made my 2d array local to the method it worked,but when I tried to make it an attribute to the class, I get thismessage “Exception in thread “main”java.lang.NullPointerException
   at Theatre.SeatingChartToZero(Theatre.java:13)
   at BoxOffice.main(BoxOffice.java:19)” For now, I justneed to output the 2d array to all zeros with having the 2d arrayan attribute to the class Theatre.

________________________________________________

import java.util.Scanner;

public class BoxOffice
{
  
   public static void main(String[] args)
   {
      
       Scanner input = new Scanner(System.in);
       int row, col;
      
      
       System.out.println(“How many rowsdo you want the theater to have?”);
       row = input.nextInt();
      
       System.out.println(“How manycolumns do you want the theater to have?”);
       col = input.nextInt();
      
       Theatre.SeatingChartToZero(row,col);
      
       input.close();

   }

}

_____________________________

public class Theatre
{
   private static int[][] c;
  
   public static void SeatingChartToZero(int row, intcolumn)
   {
       c = new int[row][];
       for(int a = 0; a < row;a++)
       {
           for(int b = 0; b< column; b++)
           {
              c[a][b] = 0;
           }
       }
      
       for(int a = 0; a < row;a++)
       {
          System.out.print(‘n’);
           for(int b = 0; b< column; b++)
           {
              System.out.print(c[a][b]);
           }
       }
   }
  
  
}

Expert Answer


Answer to Java. I need help to figure this out before I can actually do my homework. When I made my 2d array local to the method i… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *