我想做张桌子。我希望这些数字向左对齐。我不熟悉格式化,不知道为什么会出现错误。
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);
}
}
}
给你:
public class Prog122h {
public static void main(String[] args) {
System.out.format("%-10s%-10s%-10s%-10s%-10s", "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("\n%-10s%-10s%-10s%-10s%-10s", number, square, squareRoot, cube, fourthRoot, fourthRoot);
}
}
}
打印流。format()是一个可变函数,它接受多个参数而不是一个!
编写一个程序,输入三种商品的名称、数量和价格。名称可能包含空格。输出税率为6.25%的账单。所有价格应输出到小数点后两位。账单应以30个字符的列格式设置,名称为30个字符,数量为10个字符,价格为10个字符,总数为10个字符。示例输入和输出如下所示: 输出:
我很确定错误是由最后一行引起的。从我所知,它不满意我使用变量“%d”。但这不是整数的有效输入吗? 错误消息:
问题内容: 我有包含日期字符串的数据。 通常情况下,它会出现在“ Jan”中。1966年第3版的字型格式,但由于国际上的差异,不一定总是那样。 我需要读取数据并将其转换为标准日期字符串(’YYYY-MM-DD’)。 基本上这就是我到目前为止所拥有的: 问题答案: Xcode 9•Swift 4 或 Xcode 8.3.2•Swift 3.1 您可以按以下方式使用NSDataDetector:
问题内容: 我正在尝试在正在构建的android应用中发出http POST请求,但是无论我使用哪个url,Eclipse都会不断引发格式错误的URL异常。我尝试了其中一个android教程中的一行代码: 甚至触发错误。Eclipse是否会为我尝试创建的任何URL不断引发此错误,原因是什么? 问题答案: 它不是在引发异常,而是在抱怨您没有处理 它可能 (即使不会) 的可能性 ,因为这种情况下的UR
在我的班上我有日期字段: 我使用DataTimeFormat是因为我想要这样的日期格式(用于我的REST控制器): YYYY-MM-DD'T'HH:MM:SS.SSSZ,例如“2000-10-31 01:30:00.000-05:00”。 但它在JSON中转换为(JSON数组): 而不是像这样(JSON字符串): 我使用依赖项(因为转换为object,就像这个问题一样)。
我不知道如何为所有文件类型添加自定义元数据,如txt,doc,docx,xls,xlsx,ppt,pptx,pdf等。我已经尝试使用文件类setAttribute()方法为txt文件添加自定义元数据,但我得到了错误。 我没有得到我要错的地方...我得到了下面的错误