Home > Back-end >  Dear bosses, what reason is this an array?
Dear bosses, what reason is this an array?

Time:09-24

import java.util.*;

CodePudding user response:

In the n=in nextInt (); After additional
A=new int [n].

You must think you are a is static, and a new start, why still need to new?
If you can understand the following code to understand why,
int n=0;
Int a []=new int [n].//a length is how many?
Int b=n;//b?
N=5;//change after n b changed? The length of a changed?

CodePudding user response:

refer to the original poster idle, passers-by response:
import Java. Util. *;


Do a static, this is common sense, when static class loading, you've done,

You don't think that, every time a [] array will be n change new!!!!

Program to
 
Static int n;
Static int a [];

Public static void main (String [] args) {
//TODO Auto - generated method stub
Int I, j, t;
Scanner in=new Scanner (System. In);
N=in nextInt ();
A=new int [n].


}

CodePudding user response:

Should be a [] array accepted 2 repeat n (group a)
Try changing the array length to 2 n

CodePudding user response:

reference 1st floor qybao response:
in the n=. In nextInt (); After additional
A=new int [n].

You must think you are a is static, and a new start, why still need to new?
If you can understand the following code to understand why,
int n=0;
Int a []=new int [n].//a length is how many?
Int b=n;//b?
N=5;//change after n b changed? The length of a changed?

Oh oh, see, thank you for your bosses

CodePudding user response:

Static local variables can only be initialized once
  • Related