gpt4 book ai didi

java - 未知的 Java 错误

转载 作者:行者123 更新时间:2023-12-01 17:06:42 27 4
gpt4 key购买 nike

当我尝试运行时,我输入每日罚款并收到此错误“java.lang.stringindexoutofboundsexception string index out of range: 10 (in java.lang.String)” 我这样做不知道为什么。

import java.util.Scanner;
public class Fines
{
public static void main(String[] args)
{
//Makes the Scanner Object
Scanner in = new Scanner(System.in);
//Decoration
String decor = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
//Integers
int chkMonthInt;
int chkDayInt;
int chkYearInt;
int lateMonthInt;
int lateDayInt;
int lateYearInt;
int monthsLate;
int daysLate;
int yearsLate;
double rateDouble;
//Obtaining Information
System.out.print("Enter Last Name: ");
String Last = in.next();
System.out.print("Enter First Name: ");
String First = in.next();
System.out.print("Enter SSN: ");
String SSN = in.next();
System.out.print("Enter the title of the book: ");
String TitleA1 = in.next();
String TitleA2 = in.nextLine();
System.out.print("Enter the date checked out (MM/DD/YYYY): ");
String Date = in.next();
System.out.print("Enter current date (MM/DD/YYYY): ");
String Due = in.next();
System.out.print("Enter daily fine rate: ");
String Rate = in.next();
//Stringing Checkout dates
String chkMonth = Date.substring(0, 2);
String chkDay = Date.substring(3, 5);
String chkYear = Date.substring(6, 10);
//Stringing Due dates
String lateMonth = Due.substring(0, 2);
String lateDay = Due.substring(3, 5);
String lateYear = Due.substring(6, 10);
//Parsing
chkMonthInt = Integer.parseInt(chkMonth);
chkDayInt = Integer.parseInt(chkDay);
chkYearInt = Integer.parseInt(chkYear);
lateMonthInt= Integer.parseInt(lateMonth);
lateDayInt = Integer.parseInt(lateDay);
lateYearInt = Integer.parseInt(lateYear);
rateDouble = Double.parseDouble(Rate);
//Calculations
monthsLate = (lateMonthInt - chkMonthInt);
daysLate = (lateDayInt - chkDayInt);
yearsLate = (lateYearInt - chkYearInt);
//Print out the information
System.out.println("\n");
System.out.println("To: " + Last + ", " + First + "\t\tAccount: " + Last + First.substring(0, 3) + SSN.substring(6, 10));
System.out.println("From: Librarian");
System.out.println("Subject: Overdue Notice");
System.out.println(decor);
System.out.println(TitleA1 + TitleA2 + " was checked out on: " + Date);
System.out.println("This book is currently " + monthsLate + "/" + daysLate + "/" + yearsLate + " days late.");
System.out.println("Your fine has accumulated to: $" + (daysLate * rateDouble));


}

}

最佳答案

这意味着您正在尝试引用大于实际数组大小的数组索引。

关于java - 未知的 Java 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25250197/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com