私は、ユーザに自分の名前、所持している仕事の数、およびそれらの仕事の所得を尋ねるコードを書く過程にあります。次に、最高支払額と最低支払額、および入力したジョブの平均を検索します。ユーザーからの入力を取得し、それらの最高、最低、平均を見つけるにはどうすればよいですか?
イムまだユーザーが後でそれを暗唱するために、入力したもの維持しながら、平均を見つけると一緒に、最高と最低の支払う部分に問題が。
例: 入力:10000 30000 50000 は「こんにちはオードリーは、あなたは3つの仕事を持っていた最高の支払いの仕事は$ 50000を支払っ最低払っジョブは10000 $を支払ったジョブの平均賃金は、入力された$ 30000
。。。。 **** HERESにコード私が編集したが、それが正常に動作していない。私はそれがint型とdoubleとしなければならないと考えている。イムはわからないどのコードの二重であるべきで、どれがintでなければなりません。****
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class JobIncome {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner (System.in);
System.out.println("What is your first name? ");
String firstName = input.nextLine();
Scanner scan = new Scanner (System.in);
System.out.println("How many jobs have you had? ");
int jobNum = scan.nextInt();
//Declarations
int total = 0;
int average = 0;
//for loop asks for the incomes of the user's previous
//jobs and stores them into an array
int arrayOfIncomes[] = new int[jobNum];
for(int i = 1; i <= arrayOfIncomes.length; i++){
System.out.println("Enter the income of job #" + i + " : ");
arrayOfIncomes[i] = scan.nextInt();
total = total + arrayOfIncomes[i];
}
average = total/jobNum;
//Start of the code that will find the min and max
int min = arrayOfIncomes[0];
int max = arrayOfIncomes[0];
for (int i = 1; i < arrayOfIncomes.length; i++) {
if (arrayOfIncomes[i] > max) {
max = arrayOfIncomes[i];
}
}
for (int i = 1; i < arrayOfIncomes.length; i++) {
if (arrayOfIncomes[i] < min) {
min = arrayOfIncomes[i];
}
}
//Print statement that gives the user all their information
System.out.println("Hello, " + firstName + ". You have had" + jobNum +
"jobs. The highest paying job paid $" + max +
". The lowest paying job paid $" + min +
". The average pay for the " + jobNum + "jobs entered is $" + average + ".");
//Prompt asking the user if they would like to print their info into a text file
System.out.println("Would you like to output your information into a text file, yes or no? ");
String yesNo = input.nextLine();
if(yesNo.equals("yes")){
System.out.println("");
} else {
System.out.println("Goodbye.");
}
//Output code
Scanner console = new Scanner(System.in);
System.out.print("Your output file: ");
String outputFileName = console.next();
PrintWriter out = new PrintWriter(outputFileName);
//This code prints the information into the output text file
out.print("Hello, " + firstName + ". You have had" + jobNum +
"jobs. The highest paying job paid $" + max +
". The lowest paying job paid $" + min +
". The average pay for the " + jobNum + "jobs entered is $" + average + ".");
out.close();
}
残りのコードはどこにありますか? – wleao
それは私がこれまで持っていたものすべてです –
最低支払額を保持する変数と最大支払額を保持する変数を宣言します。次に、すべての支払いの合計を保持する別のものと、いくつの支払いを保持するためのものかを入力します。必要に応じてこれらの変数を更新して、必要なものを得ることができるはずです。 –