여기에 작은 문제가 있습니다. 배열의 모든 음수를 숫자 위치로 대체하려고합니다.JAVA : 배열의 숫자를 숫자로 바꾸고 인쇄하십시오.
public class oppgave33{
public static void main(String[] args) {
int[] heltall = {1, 4, 5, -2, -4, 6, 10, 3, -2};
int counter = 0;
int sumNeg = 0;
while(counter < heltall.length){
//array print out
System.out.println("array[" + counter + "] = " + heltall[counter]);
if(heltall[counter] < 0){
System.out.println(heltall[counter]);
}
//replacing negative numbers
if(heltall[counter] < 0){
heltall[counter]=counter;
}
if(heltall[counter] < 0){
sumNeg++;
}
//negative numbers position print out
if(heltall[counter] < 0){
System.out.println("Negative numbers position in array is : " + counter);
}
counter++;
}
//printing out how many negative numbers
System.out.println("There are : " + sumNeg + " negative numbers.");
}
}
최종 참고 : 내 문제는 번호를 교체하기 전에 배열, 인쇄됩니다 있다는 것입니다, 나는 그것을 교체 도착 후 배열을 인쇄 할 ... 여기 내 코드 제거하는 경우 음수가 배열에서의 위치로 대체되는 if 설정, 음수가 인쇄 된 위치 및 음수가 몇 개인지를 알 수 있습니다. 나를 도울 수 있기를 바랍니다. :) 고맙습니다!
가능한 http://stackoverflow.com/questions/39528556/replacing-array-values의 중복,하지만 아스 커의 노력이 시간. :-) –