Question: Write a program that prompts the user to enter four integers, reads them, and displays the numbers (a) in a single line separated by commas

Write a program that prompts the user to enter four integers, reads them, and displays the numbers (a) in a single line separated by commas (b) in multiple lines (as shown). Write a program that prompts the user to enter four integers, reads

Here is my code,

import java.util.Scanner; class Work { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter first integer: "); int number1 = input.nextInt();

System.out.print("Enter second integer: "); int number2 = input.nextInt(); System.out.print("Enter third integer: "); int number3 = input.nextInt(); System.out.print("Enter forth integer: "); int number4 = input.nextInt(); System.out.printf("Displaying numbers in a single line......." ); System.out.println(number1, number2, number3, number4);

} }

Can someone help me finish this with comments next to it? because I want to learn as well. Thank you

pter 02> java Welcome 1 Enter first integer: 1 Enter second integer: 2 Enter third integer: 3 Enter fourth integer: 4 Displaying numbers is a single line... 1, 2, 3, 4 Displaying numbers in multiple lines... Number 1: 1 Number 2: 2 Number 3: 3 Number 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!