我需要使用字符串、字符和一堆嵌套循环和条件语句为我的 CS 类构建这个 ISBN 校验和生成器(用于 ISBN-10 和 ISBN-13)。在这个烂摊子的某个地方,我认为有些东西正在触发无限循环,因为当我被提示输入时,我给出输入并按回车键,它只是转到一个新行并希望我输入更多数据,我猜是什么时候它应该在每次成功输入后再次提示我输入另一个,否则告诉我这是不正确的,然后仍然再次要求输入另一个。当我输入 quit 它不会结束程序并像它应该的那样显示校验和结果,而是表现出与其他输入相同的行为。
到目前为止我的代码:
/******************************************************************************
* Program Name: Lab05A - ISBN
* Program Description: Calculate ISBN-10 AND ISBN-13
* Program Author: xxxxxxxxx
* Date Created: 10/10/2018
* Change# Change Date Programmer Name Description
* ------- ------------ ------------------- ---------------------
******************************************************************************/
package lab05a;
import java.util.Scanner;
public class Lab05A {
public static void main(String[] args) {
// Input for s
Scanner input = new Scanner(System.in); // Create new scanner
System.out.println("Enter the first 9 or 12 digits of an ISBN number. Enter QUIT to exit: "); // our ever-lasting prompt
String s = input.next(); // declare string variable "s" and set it equal to next input from user.
String output10 = null; // Declaring string output10
String output13 = null; // Declaring string output13
// main while loop
while (!"QUIT".equals(s)) { //this will run as long as the program does not receive an input of "QUIT", not case sensitive.
char checkDigit;
char checkSum = '0';
if (s.length() == 9) { //if the length of the inputted string is 9 characters...
int sum = 0; // initialize sum variable
for (int i=0; i <= s.length();) {
sum = sum + ((s.charAt(i) - '0') * (i + 1));
}
if (sum % 11 == 10) {
checkDigit = 'X';
}
紫衣仙女
喵喵时光机
相关分类