importjava.util.*;publicclassTest1Question3Tax{publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);Stringinput;inttransactionNum;StringlocationCode;doublet...
import java.util.*;
public class Test1Question3Tax
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String input;
int transactionNum;
String locationCode;
double transactionAmount;
double salesTaxAmount = 0;
double totalTransaction = 0;
double tatalTax = 0;
final double aTax = 0.08; //A
final double xTax = 0.06; //C G X
final double vTax = 0.07; // F D
final double nTax = 0; // O
do
{
System.out.println("Enter you transction(only press enter will end this program):");
input = in.next();
transactionNum = Integer.parseInt(input.substring(0,4));
locationCode = input.substring(5,6);
transactionAmount = Double.parseDouble(input.substring(7));
}
while (in.hasNextLine());
}
}
这部分一直报错:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6
at java.lang.String.substring(String.java:1950)
我是想要输入 xxxx C aaaaaa 形式 然后把第一部分赋值给一个int 第二部分赋值给char或者string 最后一部分赋值给一个double。 求解怎么搞
展开