Home>
Excuse me for a rudimentary question.
About a class that outputs a table of numbers in a two-dimensional array.
package info.searchman;
public class Practice
{
public static void main (String [] args)
{
int kuku [] [] = new int [9] [];
for (int i = 0;i<9;i ++)
{
kuku [i] = new int [9];
for (int j = 0;j<9;j ++)
kuku [i] [j] = (i + 1) * (j + 1);
}
// assign values to the array kuku
for (int i = 0;i<9;i ++)
{
for (int j = 0;j<9;j ++)
System.out.printf ("% 2d", kuku [i] [j]);
System.out.println ();
}
}
}
Question ①
Does the following statement declare 9x9 and that the last parenthesis is optional?
int kuku [] [] = new int [9] [];
Question point ②
Why is the following sentence necessary?
kuku [i] = new int [9];
-
Answer # 1
-
Answer # 2
Because you don't understand the basics of Java in the first place, let's learn about that first.
If you answer here, it will be meaningless for you
Related articles
- python 3x - how to add a two-dimensional array
- java - i don't know how to add up the numbers in the list
- java - how to get data at jsp screen transition
- pass by value of java array variable
- how to use java try-catch statement
- [java] handling of array elements and null
- java - [jsp] please tell me how to use iterator
- java - cannot declare scanner twice
- java ee - i want to know how to use servletcontextlistener
- java - about array code
- java - an error occurs in the element part of the array and it does not resolve
- java - i want to know how to use if (!"variable"hasnextline()) break;
- how to use jag array in unity
- i want to know how to raise the java version to 520
- java - how to use try-catch
- java - how to read a string
- get the class of java array
- [c#] how to receive json array by post of web api
- java - how to pass values by class
- how to use java break
Related questions
- dealing with javalangnullpointerexception
- processing to sort the array with java and find the number of replacements
- java - input and output arrays using for and if statements
- java - about array return values and methods
- java - how to shuffle a graphic array and store it in another array
- java - about arraylist of 2d array
- java - description when using an array for the return value
- java - i don't know how to extract instance information directly from an array
- java - please tell me the cause of arrayindexoutofboundsexception
- java - i want to make the 4-choice quiz for super beginners expandable
What you have to do isJava so-called 2D arrays are "arrays of arrays".
For example, suppose you create an Object type array like this:
This is essentially the same if you write: (註)
The same is true if you create an array of type int [], and the following two codes have the same meaning.
註: When I tried it at hand, the bytecode was different.
All elements are null, so you need to create an array object before accessing the elements.
Not 9x9. A 9-element int [] type array is generated.
The following should work without any problem. This may be more intuitive.
In this case, kuku [i] = new int [9];is unnecessary.