任务是:
使用方法计算平方并返回答案
使用方法计算立方并返回答案
设置一个while循环来调用这两个方法并输出结果。
我想出了这个,但我也不知道如何在方法中更改变量。
public class Test {
public static void main(String args[])
{
int number = 1;
int square;
int cube;
square = squareNumber(number);
cube = cubesNumber(number, square);
System.out.println("\nNumber\tSquare\tCubes");
while(number <= 5)
{
System.out.printf(" %d\t %d\t %d\n", number, square, cube);
number++;
}//end Loop
}//end main
private static int squareNumber(int number)
{
int square;
square = number * number;
return square;
}//end squares method
private static int cubesNumber(int number, int square)
{
int cube;
cube = square * number;
return cube;
}//end squares method
} //end class