將函數放在類中後,我的數組中得到零(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 – 2013-03-11 21:19:15
我現在問的問題與我以前問過的問題不同。它只是代碼的轉發,要求提出一個不同的問題,因爲我的另一篇文章針對相同的代碼進行了編輯,以滿足我之前詢問的問題的需求。由於我在提出一個新問題,因此我建議爲了社區的利益,爲此做一個新的職位。請如果你沒有回答我的問題,我會請你停止在我的文章發送垃圾郵件。 – 2013-03-11 21:29:03