2
이것은 매우 흥미 롭습니다. 최선을 다해 설명하기 전에 코드를 보여주고 내가 의미하는 바를 이해하게 될 것입니다. 시퀀스에서 숫자 건너 뛰기 Java
이
은 코드 다음addaccount()
방법 라인의 주를 가지고, 그래서 지금 당신이 어려운 문제는이 통지하는 코드를 볼 것을
public class Qn3 {
static BigDecimal[] accbal = new BigDecimal[19];
private static Integer[] accnums = new Integer[19];
public static void main(String[] args) {
addaccount();
}
public static void addAccount() {
int i = 0, accno, input, j, check;
BigDecimal accbala;
DecimalFormat df = new DecimalFormat("0.00");
Scanner sc = new Scanner(System.in);
Scanner in = new Scanner(System.in);
accnums[1] = new Integer(1);
while (accnums.length >= count(accnums)) {
System.out.print("Enter the account number: ");
while (sc.hasNext("[0-9]{7}")) {
accno = sc.nextInt();
System.out.print("Enter account balance: ");
accbala = in.nextBigDecimal();
for (j = 0; j < accnums.length; j++) {
if (accnums[j] == null)
break;
else if (accnums[j].equals(accno)) {
break;
}
}
if (j == accnums.length) {
System.out.print("No more than 20 accounts can be added.");
} else if (accnums[j] != null) {
if ((accnums[j].equals(accno)))
System.out.println("Account already exists");
break;
} else {
accnums[j] = accno;
accbala = accbala.setScale(2, RoundingMode.HALF_UP);
accbal[j] = accbala;
check = j;
System.out.println("Current number of accounts in the system: "
+ (check + 1)
+ "\nNumber of accounts still can be added: "
+ (20 - (check + 1)));
}
}
while (!sc.hasNext("[0-9]{7}")) {
System.out.println("Wrong NRIC");
break;
}
while (accnums.length <= count(accnums)) {
System.out.println("20 accounts have already been created");
break;
}
break;
}
}
private static int count(Integer[] array) {
int count = 0;
// accnums = new Integer[] {1,2};
for (int index = 0; index < array.length; index++) {
if (array[index] != null) {
count++;
}
}
// System.out.println("You have used " + count + " slots");
return count;
}
}
곳
System.out.println("Current number of accounts in the system: "+(check+1)+"\nNumber of accounts still can be added: "+(20 - (check+1)));
이 줄을 첫 번째 check+1
줄 다음 1 다음 날 줄 것이다 3! 그리고 나서 다음에 내가 4를주고 다시 5를주는 등의 방법으로 2를 어떻게할까요?
코드 벽을 게시 할 필요가 없습니다. 이러한 종류의 문제는 디버거를 사용하여 해결할 수 있습니다. –
@LuiggiMendoza 나는 형제 였어. .. 나는 여전히 가장자리에있다. ..btw라고 언급해라. – JackyBoi
Jayson의 게시물을 답으로 표시하는 것을 잊지 마라. –