Question

In Java chapter 7 Arrays. Ask the user for five names. Output those names. Put an...

In Java chapter 7 Arrays.

Ask the user for five names. Output those names. Put an integer before each name to indicate the ordering

Here are the required output

Test Case 1

Standard Input                
BillENTER
SteveENTER
MarkENTER
ElonENTER
Henry
Enter five names\n
Enter friend 1\n
Enter friend 2\n
Enter friend 3\n
Enter friend 4\n
Enter friend 5\n
Here are all of those names\n
Friend 1 is Bill\n
Friend 2 is Steve\n
Friend 3 is Mark\n
Friend 4 is Elon\n
Friend 5 is Henry\n

Test Case 2

Standard Input                
JerryENTER
ElaineENTER
GeorgeENTER
KramerENTER
Newman
Enter five names\n
Enter friend 1\n
Enter friend 2\n
Enter friend 3\n
Enter friend 4\n
Enter friend 5\n
Here are all of those names\n
Friend 1 is Jerry\n
Friend 2 is Elaine\n
Friend 3 is George\n
Friend 4 is Kramer\n
Friend 5 is Newman\n

Test Case 3

To prevent hardcoding, this test case is hidden. To pass this case, be sure that all the programming requirements are met.

This what i have so far im having a hard time to attach the name on the last line

import java.util.Scanner;

public class PS9_4
{
    public static void main (String[] args)
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Enter five names");
        int[] values = new int[5];

        for (int subscript = 0; subscript < values.length; subscript++)
        {
            System.out.println("Enter friend " + (subscript + 1));
            String NAME1 = keyboard.nextLine();
        }
        System.out.println("Here are all of those name");
        for (int subscript = 0; subscript < values.length; subscript++)
        {
            System.out.println("Friends " + (subscript + 1));
        }
    }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class PS9_4 {
    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Enter five names");
        String[] values = new String[5];

        for (int subscript = 0; subscript < values.length; subscript++) {
            System.out.println("Enter friend " + (subscript + 1));
            values[subscript] = keyboard.nextLine();
        }
        System.out.println("Here are all of those name");
        for (int subscript = 0; subscript < values.length; subscript++) {
            System.out.println("Friends " + (subscript + 1) + " is " + values[subscript]);
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
In Java chapter 7 Arrays. Ask the user for five names. Output those names. Put an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Question where in chapter 7 Arrays. Ive done the code but im still having trouble...

    Java Question where in chapter 7 Arrays. Ive done the code but im still having trouble with the inequality Here my code import java.util.Scanner; public class PS10_5 { public static void main(String args[]) { int[] mynum = new int[5]; int count = 0; int[] lottery = {8,13,27,53,54}; Scanner keyboard = new Scanner(System.in); System.out.println("Check your lottery numbers here!"); for(int subscript=0; subscript<5; subscript++) { System.out.println("Enter number " + (subscript +1) + ":"); mynum[subscript] = keyboard.nextInt(); } for(int subscript=0; subscript<5; subscript++) { for...

  • Write a program in Java. Ask the user how many integers that he/she wants to enter....

    Write a program in Java. Ask the user how many integers that he/she wants to enter. Using a for loop, ask the user for that many integers. Then, display all those integers. view required output Standard Input                 20ENTER 500ENTER 400ENTER 300ENTER 550ENTER 600ENTER 700ENTER -3ENTER 0ENTER 50ENTER 60ENTER 40ENTER 13ENTER 14ENTER 80ENTER 90ENTER 100ENTER 777ENTER 1024ENTER 20ENTER 22 How many integers do you have? (Max 20)\n Enter element for subscript 0\n Enter element for subscript 1\n Enter element for...

  • Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent...

    Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent debugging * problems. Solve one at a time, uncommenting the next * one only after the previous problem is working correctly. */ public class FindTheErrors { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); /* * Problem 1 Debugging * * This problem is to read in your first name, * last name, and current year and display them in *...

  • Java programming question: Here is the feedback I received "sort fails. Use Arrays class method to...

    Java programming question: Here is the feedback I received "sort fails. Use Arrays class method to sort." The actual question: Write a program as follows: Declare a five element array of Strings. Use a for loop and keyboard input to populate the array with the names of five friends. Sort the array in alphabetical order. Use a foreach loop to print the sorted array of friends, all on one line. Sample Output (inputs in italics) Enter the names of five...

  • *JAVA Prompt the user for a movie name. Output the three movies that come alphabetically before...

    *JAVA Prompt the user for a movie name. Output the three movies that come alphabetically before the one entered. I need help correcting my code. I'm unsure why I am getting a name, year, and genre in my output. Input: Jericho Output: Similar title finder. Enter a movie name.\n Here are the 3 movies that are listed before the one you entered\n Jeremy Paxman Interviews...\n Jeremy Taylor\n Jeremy Vine Meets...\n Current output: Similar title finder. Enter a movie name.\n Here...

  • Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class...

    Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...

  • I need to add a method high school student, I couldn't connect high school student to...

    I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...

  • design two java classes The example of output would be this: user puts the amount of...

    design two java classes The example of output would be this: user puts the amount of money: (for example 9000) I'm going to get three things 1. Cellphone cost: 3000 2. Laptop cost: 6000 3. Macbook cost: 4000 From now on, my balance would be (+balance) and I bought cellphone, laptop, (since there is not enough amount of money, I can only buy cellphone and laptop. if there is enough money then it can buy all things) so I have...

  • For this code after case 0, I need it to ask the user if they would...

    For this code after case 0, I need it to ask the user if they would like to see the menu again and some type of if statement or loop to ask them yes or no and if yes print again and if no end program. So it would ask if they would like to see the menu again then ask what their choice is. If yes print menu and if no end program. import java.util.InputMismatchException; import java.util.*; import java.io.*;...

  • Could you help me pleas , this is my code I want change it to insert...

    Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT