标题: JAVA PROBLEM [打印本页] 作者: jayte2168 时间: 2014-10-15 09:36 AM 标题: JAVA PROBLEM The below coding is incomplete and in a messy order, so i'm finding someone to arrange them for me.
This program is to test the perfect number, excessive number and decessive number.
In the program:
1)prompt the user for input
2)inputs from user:
1) amount of number to be tested (how many times to loop)
For example,
Please enter the numbers of value to be tested.
4
Please enter the 1st number.
60
(then the result)
Please enter the 2nd number.
80
(then the result)
Please enter the 3rd number.
100
(then the result)
Please enter the 4st number.
500
(then the result)
2) the whole number (between 6-1000)
3)check that the values entered fall within the valid ranges, if not, show warning and prompt to re-enter
4)after input, begin to loop
5)output:
1) list of divisor of the input
2) sum of the divisors
3) message state the result
The output only display the proper divisor.
import java.util.*;
public class Number {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
while (true)
{
System.out.println("How many number do you want to test? ");
try
{
int size = in.nextInt();
System.out.println("Enter a number,x which 6 <= x <= 1000");
List<Integer> numbers = new ArrayList(0);
for (int i=0;i<size;i++) {
System.out.println("Number "+(i+1)+"?");
int input = in.nextInt();
numbers.add(input);
}
for (Integer num : numbers) {
printResult(sumOfDivisors(getFactors(num)), num);
}
int input = in.nextInt();
if (inputError(input))
{
System.out.println("Input Range Error!");
System.out.println();
continue;
}
List<Integer> factors = getFactors(input);
printFactors(factors);
int sum = sumOfDivisors(factors) - input;
System.out.printf("Sum of divisors: %d", sum);
System.out.println();
printResult(sum, input);
System.out.println();
}
catch (InputMismatchException e)
{
in.next(); // prevent repeat reading
System.out.println("Input Type Error!");
System.out.println();
continue;
}
}
}
private static boolean inputError(int input)
{
if (input < 6 || input > 1000) return true;
return false;
}
private static List<Integer> getFactors(int n)
{
List<Integer> factors = new ArrayList<Integer>(0);