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

  • SEARCH
  • Home
  • 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 8858065
In Process

The Archive Base Latest Questions

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

So I am writing a program for school that handles usernames and passwords. Its

  • 0

So I am writing a program for school that handles usernames and passwords. Its supposed to take prompt for user names and passwords for 3 users. Then display the username and asterisk for the length of the password. I have pretty much everything I need including how to print the asterisk for the length of the password on the same line:

//int asterix =password[x].length();
 * for (int y=0; y<asterix ;y++){
 *                  System.out.print("*");
 *              }
 */

My issue is I need to format the output like this:

USER ID                 PASSWORD

howdyDoodie              ***********
batMan                   ************
barneyRubble             ************

So far my code looks like this:

  public class test{

    /**
     * 
     * @param args
     */





    public static void main(String[] args){
        String[] user = new String[3];
        String[] password = new String[3];

        // Prompt for Username and Password and loop 3 times adding to next value in array
        for(int x=0; x<=2;x++){

        user[x] = JOptionPane.showInputDialog(null,"Enter Username: ");
        password[x] = JOptionPane.showInputDialog(null,"Enter Password: ");
        // Test number of loops
        //System.out.println(x);

        }

        //Field Names Print

        System.out.printf("\n%s\t%10s","Username","Password");

        for(int x=0; x<=2;x++){
            System.out.printf("\n%s\t%15s",user[x],password[x]);

        }

     System.exit(0);

    }
    /*
     * //int asterix =password[x].length();
     * for (int y=0; y<asterix ;y++){
     *                  System.out.print("*");
     *              }
     */

} // End of Class

I can’t figure out how to get the asterisk to print out and use the formatting.

  • 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-14T14:44:33+00:00Added an answer on June 14, 2026 at 2:44 pm

    You need a nested loop. Move the for loop printing the asterisk (*) inside the for loop printing username and password for all users.

    Your loop should look like this. It is not tested, but you can work it around to get desired output.

    System.out.printf("%-20s\t%-10s","Username","Password");
    
    for(int x=0; x<=2;x++) {
    
         System.out.printf("%-20s\t",user[x]);  // Just print user here
    
         int asterix =password[x].length();
         for (int y=0; y<asterix ;y++){  // For the length of password 
             System.out.print("*");      // Print *
         }
         System.out.println();   // Print newline to move to the next line
    }
    

    %-20s\t means username takes 20 spaces, left-aligned, and add a tab after it.

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

Sidebar

Related Questions

I'm writing a program for a school project that is supposed to emulate the
I'm writing a program that handles DBs and writes any changes into ListView for
So I am writing a Ruby program for school that changes the value of
I'm writing a program using Xcode for school that requires we use the open()
Im writing a program for my school in which users have to enter a
I am writing a program for school where the user inputs name, hours worked,
I am writing a small program for our local high school (pro bono). The
Im writing a program that should read input via stdin, so I have the
I am currently writing a program using Weka that builds a model (using one
I'm writing a program that's parsing an XML file to java objects using smooks.

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.