Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8853983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:46:44+00:00 2026-06-14T13:46:44+00:00

package homework4; import java.util.Scanner; public class Prog4 { static Scanner scanner = new Scanner(System.in);

  • 0
package homework4;
import java.util.Scanner;
public class Prog4 {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args)
{   CreditCardNumber[] cred1;
    CreditCardNumber cred2 = getInput();
    Display("The complete number from your input:", cred2);
    cred1 = getInputArray();
    DisplayArray(cred1);
    TryAnother(cred1);
}

public static CreditCardNumber getInput() {
    String ID;
    String accNum;
    CreditCardNumber tempCred;      
    System.out.printf("Please enter issuer ID:");
    ID = scanner.next();
    System.out.printf("Please enter account number:");
    accNum = scanner.next();
    tempCred = new CreditCardNumber(ID, accNum);

    return tempCred;
}
public static void Display(String ch, CreditCardNumber cred2)
{

    System.out.println(ch);
    System.out.println(cred2.toString().replaceAll(".{4}", "$0   "));       
}

public static CreditCardNumber[] getInputArray()
{
    CreditCardNumber[] tempArray;
    String tempID;
    int size;       
    System.out.printf("Please enter size of the aray:");
    size = scanner.nextInt();
    if(size < 1)
    {
        size = 1;
    }
    tempArray = new CreditCardNumber[size];
    System.out.printf("Please enter issuer ID:");
    tempID = scanner.next();
    for(int i = 0; i < tempArray.length; i++)
    {
        tempArray[i] = new CreditCardNumber();
        tempArray[i].CreateCred(tempID);
    }

    return tempArray;
}

public static void DisplayArray(CreditCardNumber[] cred1)
{
    for(int i = 0; i< cred1.length; i++)
    {
        Display("Credit Card # " + i+":" + '\n', cred1[i]);
    }
    System.out.println();
}

public static boolean TryAnother(CreditCardNumber[] cred1)   
{
    String s;
    System.out.printf("Get more credit card numbers? (n for no):");
    s = scanner.next();
    while(s.charAt(0) != 'N' && s.charAt(0) != 'n')
    {                                       
            cred1 = getInputArray();
            DisplayArray(cred1);    
            if(s.charAt(0) != 'N' && s.charAt(0) != 'n')
            TryAnother(cred1);
    }       


    return false;   
}
}

hi i have a problem with the Tryanother method when i answer no the process doesn’t terminate but instead prompt user to ente the size of array again like this:

Please enter issuer ID:321321
Please enter account number:654654654
The complete number from your input:
3213   2165   4654   6549   
Please enter size of the aray:7
Please enter issuer ID:789789
Credit Card # 0:

7897   8987   8895   1653   
Credit Card # 1:

7897   8935   5880   5197   
Credit Card # 2:

7897   8997   8152   8134   
Credit Card # 3:

7897   8996   1605   8067   
Credit Card # 4:

7897   8953   2006   5521   
Credit Card # 5:

7897   8964   3319   8191   
Credit Card # 6:

7897   8986   1830   7068   

Get more credit card numbers? (n for no):y
Please enter size of the aray:3
Please enter issuer ID:345345
Credit Card # 0:

3453   4590   2392   9734   
Credit Card # 1:

3453   4549   5025   1905   
Credit Card # 2:

3453   4504   2989   0927   

Get more credit card numbers? (n for no):n
Please enter size of the aray:

as you can see when I enter ‘y’ the program work, it prompt user to enter the size of array, but when i enter ‘n’ instead of terminating the program prompt user to enter the size of the array

how can i fix this problem?

thank you in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:46:46+00:00Added an answer on June 14, 2026 at 1:46 pm

    Just noticed you have s.charAt(0) != 'N' && s.charAt(0) != 'n' inside your while loop and also calling the same function recursively within the loop.

    Change it to if(s.charAt(0) != 'N' && s.charAt(0) != 'n')

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package homework4; import java.util.Scanner; public class Prog4 { static Scanner scanner = new Scanner(System.in);
package GC; import java.util.Scanner; public class main { public static void main(String args[]) {
package com.test01; public class test01 { public static void main(String[] args) { System.out.println(hi); }
package pack; public class sample{ public static void main(String input[]) { NumberFormat numberFormat =
package org.study.algos; public class Study { public static void main(String[] args) { A a
package homework5; import java.io.*; import java.util.Arrays; public class Main { /** * @param args
package src; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Command { public static
package javaapplication1; import java.io.*; /** * * @author simon */ public class Main {
package pkgPeople; import java.io.Serializable; import java.text.DecimalFormat; public class Person implements Serializable{ private String name;
package macroreader; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class MacroReader { public static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.