Answer to Question #115636 in Java | JSP | JSF for Aryan

Question #115636
Create the java program called Product that prompts the user to enter names of hardware devices. The program includes a sentinel loop with a value of ### that stops the input from the user. Include a counter variable called inputnum inside the loop, that counts the number of hardware devices the user entered. Using a system statement inside the loop, display the names of hardware devices the user entered. Include a dialog box outside the loop that displays the counter variable value (number of hardware device names entered by the user).
1
Expert's answer
2020-05-15T09:37:36-0400
import javax.swing.*;
import java.util.Scanner;

public class Product {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long inputnum = 0;
        String s = "";
        while (!s.equalsIgnoreCase("###")) {
            System.out.println("Enter name of hardware device");
            if (!(s = scanner.nextLine()).equalsIgnoreCase("###")) {
                System.out.println("Hardware device: " + s);
                inputnum++;
            }
        }
        JOptionPane.showMessageDialog(null, "Number of entered names: " + inputnum);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS