だから私は自分の問題を理解して成功しましたが、それでも、teranary演算子を使用してこの構文を単純化できるかどうか、そしてどのようにすればよいかについて、誰かの意見を求めています。
import java.util.Scanner;
import java.io.*;
public class Midterm
{
public static void main(String[]args) throws Exception
{
final String FILE = "integers.txt";
final String RELATIVE_DIRECTORY_FILE = "integers.txt ";
int positiveNumberCount = 0,
negativeNumberCount = 0;
String dataItem;
double sum = 0;
double sumForAverage = 0;
double average = 0;
File inputFile = new File(RELATIVE_DIRECTORY_FILE);
if(!inputFile.exists())
{
System.out.printf("%n%s%s%s", "The file, ", RELATIVE_DIRECTORY_FILE, " does not exist");
}
if(inputFile.exists())
{
System.out.printf("%s%s%s", "The file ", RELATIVE_DIRECTORY_FILE, "was found");
Scanner file = new Scanner(inputFile);
//***if i need to use a delimiter *****
//file.useDelimiter(",") where in between " " is my type of delimiter
while(file.hasNext())
{
dataItem = file.nextLine();
double numericalDataItem = Double.parseDouble(dataItem);
boolean isPositive = false;
boolean isNegative = false;
if(numericalDataItem > 0)
{
isPositive = true;
positiveNumberCount++;
}
else if(numericalDataItem < 0)
{
isNegative = true;
negativeNumberCount++;
}
sum += Double.parseDouble(dataItem);
sumForAverage = positiveNumberCount + negativeNumberCount;
average = sum/sumForAverage;
}
System.out.printf("%n%s%d%n%s%d%n%s%.2f%n%s%.2f", "Positive Number Count: ", positiveNumberCount,
"Negative Number Count: ", negativeNumberCount, "Sum Of Numbers: ", sum, "Average of Numbers: ", average);
}
}
}