0
我想制作一张桌子。我希望这些数字在左边是合理的。我是新手格式化,我不知道为什么我得到一个错误。Uknown格式转换异常错误?
public class Prog122h
{
public static void main (String[] args)
{
System.out.println("Number Square Square Root Cube 4th Root"); // heading
for (int number = 1; number <= 20; number++) // repeats finding the square and square root of the number until 40. increments number by 1
{
//finds square using math class
int square= (int) Math.pow(number, 2);
// finds square root of the number using math class
double squareRoot= (Math.sqrt(number));
squareRoot= Math.round (squareRoot* 10000.0)/10000.0;
//finds the cube of the number
int cube= (int) Math.pow(number, 3);
//finds the 4th root of the number
double fourthRoot= Math.pow(number, 1.0/4);
fourthRoot= Math.round (fourthRoot* 10000.0)/10000.0;
//output of table
System.out.format("%-, "+number+" %-, "+square+" %-, "+squareRoot+" %-, " +cube+" %-, "+fourthRoot);
}
}
}