Home > Back-end >  In JAVA this why cannot achieve the minimum, strives for the answer
In JAVA this why cannot achieve the minimum, strives for the answer

Time:09-27

String num.
Int I, k, N.
System. The out. Print (" N value is: ");
C=new Scanner Scanner System. (in);
N=c.n extInt ();
Int [] s=new int [N].
K=s [0];
InputStreamReader isr=new InputStreamReader (System. In);
BufferedReader br=new BufferedReader (isr);
Try {
System. The out. Print (" Input N Numbers: \ N ");
for(i=0; i{
System. The out. Print (" please enter the first "+ (1 + I) +" number: ");
Num=br. ReadLine ();
S [I]=Integer. The parseInt (num);
}
for(i=0; i{
If (k> S [I])
{
K=s [I];
}
}
System. The out. Println (" minimum value is: "+ k);
}
The catch (IOException e) {}

CodePudding user response:

Your sort code is as follows:
 
for(i=0; i{
If (k> S [I])
{
K=s [I];
}
}

I'll give you a change to the
 
K=s [0];
for(i=0; i{
If (k> S [I])
{
K=s [I];
}

}

See the difference? You to assign a k s [] had nothing to do with the value of 0, if you give s all array elements are greater than zero, you won't get the s array inside the minimum value, because they are bigger than 0

CodePudding user response:

K=s [0]; On the array after the assignment

CodePudding user response:

reference 1/f, dear Joe reply:
your sort code is as follows:
 
for(i=0; i{
If (k> S [I])
{
K=s [I];
}
}

I'll give you a change to the
 
K=s [0];
for(i=0; i{
If (k> S [I])
{
K=s [I];
}

}

See the difference? You to assign a k s [] had nothing to do with the value of 0, if you give s all array elements are greater than zero, you won't get the s array inside the minimum value, because they are bigger than 0

Thank you, I didn't see a reply

CodePudding user response:

reference 1/f, dear Joe reply:
your sort code is as follows:
 
for(i=0; i{
If (k> S [I])
{
K=s [I];
}
}

I'll give you a change to the
 
K=s [0];
for(i=0; i{
If (k> S [I])
{
K=s [I];
}

}

See the difference? You to assign a k s [] had nothing to do with the value of 0, if you give s all array elements are greater than zero, you won't get the s array inside the minimum value, because they are bigger than 0

Thank you, just see the reply, very useful, hey hey

CodePudding user response:

refer to the second floor weixin_42141668 response:
to k=s [0]; On the array assignment after

Thank you, know how to do it, just see the reply, thanks

CodePudding user response:

reference 4 floor weixin_45738136 response:
Quote: reference 1/f, dear Joe reply:
your sort code is as follows:
 
for(i=0; i{
If (k> S [I])
{
K=s [I];
}
}

I'll give you a change to the
 
K=s [0];
for(i=0; i{
If (k> S [I])
{
K=s [I];
}

}

See the difference? You to assign a k s [] had nothing to do with the value of 0, if you give s all array elements are greater than zero, you won't get the s array inside the minimum value, because they are bigger than 0

Thank you, just see the reply, very useful, hey hey

Solved? If solved please have post bar, ha ha
  • Related