In: Computer Science
Problem1: In this problem we will ask the use to enter a value greater than 1,000 and less than 1,000,000 without a comma and the program will add the comma.
import java.util.*;
import java.io.*;
import java.math.*;
class Problem1
{
int value;
public Problem1(int v)
{
value = v;
}
String addComma()
{
String commaNumber;
int thousands;
int hundreds;
thousands = this.value/1000;
hundreds = this.value%1000;
commaNumber = thousands + "," +
hundreds;
return commaNumber;
}
};
class Problem1Tester
{
public static void main(String[] args)
{
Scanner in = new
Scanner(System.in);
System.out.println("enter a number
between 1000 and 1000000\n");
int inputVariable =
Integer.parseInt(in.nextLine());
Problem1 probObj = new
Problem1(inputVariable);
System.out.println("output: " +
probObj.addComma());
}
}