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 8877949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:35:38+00:00 2026-06-14T19:35:38+00:00

I have a question with the display array method. I can’t figure how to

  • 0

I have a question with the display array method. I can’t figure how to make it to format this:

Credit Card # 4: 
8908 9014 8812 1331

What I need to do is for each array element call the display method and pass the index of the array in a string for the label, I just cant figure out how to do this, I tried this but it is wrong:

System.out.println(display("Credit Card # %d", cred1[i]));

Can anyone please suggest a way to do this?

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();
}

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();
    System.out.print(tempArray.length);
    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++)
    {
        System.out.println(display("Credit Card # %d", cred1[i]));
    }
}

public static boolean TryAnother()
{
    String s;
    System.out.printf("Get more credit card numbers? (n for no):");
    s = scanner.next();
    if(s.charAt(0) != 'N' && s.charAt(0) != 'n')
    {
        return true;
    }
    return false;
}
}
  • 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-14T19:35:40+00:00Added an answer on June 14, 2026 at 7:35 pm

    sounds like all you need is a new line character. For example.

    System.out.println("Credit Card # " + cred1[i] + "\n" + cred2.toString());
    

    The new line character “\n” will drop the output onto it’s own line.

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

Sidebar

Related Questions

Very simple question... I have an array of pixels, how do I display them
I have a question about returning an array from one method back to main.
I'm new with vim's taglist plugin and have a question regarding display style of
I have question. I have some app on facebook and getting this error Fatal
I have question i.e how can i select a previous div CODE:- if($i >
I have question regarding the SQLAlchemy. How can I add into my mapped class
I know that this question might have been asked like 100 times, but, believe
I made this question in this if then else to display 2 views on
It's a calculator. I have a display where I can put digits and variables
I have seen this question already answered here but when I tried the same

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.