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).
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 4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started