0
import java.io.*;
import java.util.Scanner;
public class Project4
{
    public static void main(String[] args)
    throws FileNotFoundException
    {
        Scanner input = new Scanner(new File("data4.txt"));
        PrintWriter out = new PrintWriter(new File("output1.txt"));
        out.printf(" Tanner Triggs  Project 4\n");
        out.printf(" Due 10/18/13 Professor Barker");
        y=InputNumber(); 
        int divisor = 2;
        ctr = 0;
        out.printf("\n For the number %4d the prime factors are", InputNumber);
        ctr++;

        do
        {
            int remainder = InputNumber% divisor;
            if (remainder = 0)
            {
                out.print(",  " +divisor);
                InputNumber = InputNumber/divisor;
            }
            else
            {
                divisor++;
            }
        }while (divisor!=y);
        InputNumber = input.nextInt();

        out.printf("\n\n%d set of numbers factored" , ctr);
        input.close();
        out.close();
    }
}
4

1 回答 1

0

您从未声明过名为y. Java 是强类型的,这意味着您必须告诉它每个变量的类型(与 Ruby 或 Javascript 等语言相比,您可以将任何类型的值放入任何变量中)。在您的作业上方添加一行int y;,或进行作业int y = InputNumber();

此外,您使用两个InputNumbers,一个方法(带括号)和一个变量(不带),但您也从未声明其中任何一个。将变量和方法命名为同一个东西通常是个坏主意。它很快就会变得混乱。最后,Java 习惯将方法名和变量名的首字母小写,以区别于类名。

于 2013-10-17T17:56:50.240 回答