提问人:AsderSynth 提问时间:10/24/2023 最后编辑:khelwoodAsderSynth 更新时间:10/24/2023 访问量:33
我不能在动态场景中使用制表符空间而不是列宽说明符
cant I use tab spaces instead of column width specifier in dynamic scenario
问:
import java.util.Scanner;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Get the employee name and basic salary
System.out.println("Enter the employee name:");
String name = scanner.nextLine();
System.out.println("Enter the basic salary:");
double basicSalary = scanner.nextDouble();
// Calculate the DA and SA based on the basic salary
double da = 0;
double sa = 0;
if (basicSalary <= 10000) {
da = basicSalary * 0.1;
sa = basicSalary * 0.05;
} else if (basicSalary <= 20000) {
da = basicSalary * 0.12;
sa = basicSalary * 0.08;
} else if (basicSalary <= 30000) {
da = basicSalary * 0.15;
sa = basicSalary * 0.1;
} else {
da = basicSalary * 0.2;
sa = basicSalary * 0.12;
}
// Calculate the gross salary
double grossSalary = basicSalary + da + sa;
// Display the employee salary information in tabular format
System.out.println();
System.out.printf("%-20s%-15s%-15s%-20s%-15s%n", "Name", "Basic", "DA", "Spl. Allowance", "Gross Salary");
System.out.printf("%-20s%-15.2f%-15.2f%-20.2f%-15.2f%n", name, basicSalary, da, sa, grossSalary);
}
在上面的代码中,有没有办法以相同的格式显示,但使用简单的逻辑,如“/t”?
我尝试只输入“/t”,但在某些情况下不起作用。 此外,在这方面不允许使用字符串函数。
答: 暂无答案
评论
\t
/t
\t
/t
/
t