155k views
2 votes
[JAVA] Write a program that reads a number between 1,000 and 999,999 from the user and prints it with a comma separating the thousands.

Here is a sample dialog;
Please enter an integer between 1000 and 999999: 23456
Output: 23,456

1 Answer

3 votes

Answer:

import java.util.Scanner;

public class Comma {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("please enter an ineger between 1,000 and 999,999");

String number = input.nextLine();

System.out.println(number.replace(",", ""));

}

}

Step-by-step explanation:

here is the solution

User Victor Chekalin
by
5.1k points