클래스에 함수를 넣으면 결과가 제 배열로 제로 (0)가됩니다. 왜 그런가요? 변경된 사항 없음 수업에 붙여 넣기 만하면됩니다. 그 일을하기 위해 수업에 넣어야 할 것이 있습니까?배열의 0이 아닌 값
import java.util.*;//import library
class Input
{
public Input (int size,int startV,int endingV)
{
//declarations of variables
double difference;
double[] array= new double[size];
array[0]=startV;
//calculating the difference to add on each number in the array
difference=(endingV-startV)/size;
for (int counter=1;counter<size;counter++) //for loop to fill the array
{
array[counter]=array[counter-1] + difference;
}
}
public Input enter(int size,int startV,int endingV)
{
//declarations of variables
double difference;
double[] array= new double[size];
array[0]=startV;
//calculating the difference to add on each number in the array
difference=(endingV-startV)/size;
for (int counter=1;counter<size;counter++) //for loop to fill the array
{
array[counter]=array[counter-1] + difference;
}
return this;
}
}
class Show
{
public Show (int size,double[] array)
{
for (int i=0;i<size;i++) //for loop to print the array
System.out.println("This is the array " + i+ ": " + array[i]);
}
public Show print(int size,double[] array)
{
for (int i=0;i<size;i++) //for loop to print the array
System.out.println("This is the array " + i+ ": " + array[i]);
return this;
}
}
public class Assignment2
{
public static void main(String[] args)
{
//declaring variables
int startV,endingV;
int size=0;
System.out.print("Give the size of the array:");//Print message on screen
size = new Scanner(System.in).nextInt();//asking for the size of array
double[] array= new double[size]; //creation of array
System.out.print("Give the starting value of the array:");
startV = new Scanner(System.in).nextInt();//asking for the starting value of array
System.out.print("Give the ending value of the array:");
endingV = new Scanner(System.in).nextInt();//asking for the last value of array
//calling the functions from the other classes
Input enter= new Input(size,startV,endingV);
Show print= new Show(size,array);
}
}
만약 내가 방금 숙제하고있는 증명이 아니라면 무엇을 말할 지 모르겠다. m8 –
나는 이전에 물어 본 것과는 다른 질문을하고있다. 같은 코드에 대한 다른 포스트가 내가 전에 물어 본 질문의 필요에 맞게 편집 된 이후 다른 질문을하는 코드의 재 게시. 나는 새로운 질문을하고 있기 때문에 커뮤니티의 이익을 위해 새로운 포스트에 그것을하도록 권고 받았다. 제 질문에 대한 답변이 없으면 제 우편에 스팸을 중단 해달라고 부탁드립니다. –