私は、ユーザーが8歳の異なる従業員の年齢と希望退職年齢を入力して、その情報を退職する年数とともに表示するプログラムを作成しています。ここに私のコードは次のとおりです。この混乱の一部を軽減するための方法彼らのかもしれ場合クラッタを減らすには?
import java.util.Scanner;
public class Retirement {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[][] ages = new int[8][2];
System.out.println("Enter the employees current ages (between 19 and 70), and enter their desired retirement ages (62, 66, or 70).");
for (int i = 0; i < ages.length; i++) {
ages[i][0] = input.nextInt();
ages[i][1] = input.nextInt();
}
int employee1 = (ages[0][1] - ages[0][0]);
int employee2 = (ages[1][1] - ages[1][0]);
int employee3 = (ages[2][1] - ages[2][0]);
int employee4 = (ages[3][1] - ages[3][0]);
int employee5 = (ages[4][1] - ages[4][0]);
int employee6 = (ages[5][1] - ages[5][0]);
int employee7 = (ages[6][1] - ages[6][0]);
int employee8 = (ages[7][1] - ages[7][0]);
System.out.println("The current age and desired retirement age for Employee #1 is: " + (ages[0][0]) + " and " + (ages[0][1]) + ".");
System.out.println("Employee #1 has to work " + (employee1) + " years before they can retire.");
System.out.println("\nThe current age and desired retirement age for Employee #2 is: " + (ages[1][0]) + " and " + (ages[1][1]) + ".");
System.out.println("Employee #2 has to work " + (employee2) + " years before they can retire.");
System.out.println("\nThe current age and desired retirement age for Employee #3 is: " + (ages[2][0]) + " and " + (ages[2][1]) + ".");
System.out.println("Employee #3 has to work " + (employee3) + " years before they can retire.");
System.out.println("\nThe current age and desired retirement age for Employee #4 is: " + (ages[3][0]) + " and " + (ages[3][1]) + ".");
System.out.println("Employee #4 has to work " + (employee4) + " years before they can retire.");
System.out.println("\nThe current age and desired retirement age for Employee #5 is: " + (ages[4][0]) + " and " + (ages[4][1]) + ".");
System.out.println("Employee #5 has to work " + (employee5) + " years before they can retire.");
System.out.println("\nThe current age and desired retirement age for Employee #6 is: " + (ages[5][0]) + " and " + (ages[5][1]) + ".");
System.out.println("Employee #6 has to work " + (employee6) + " years before they can retire.");
System.out.println("\nThe current age and desired retirement age for Employee #7 is: " + (ages[6][0]) + " and " + (ages[6][1]) + ".");
System.out.println("Employee #7 has to work " + (employee7) + " years before they can retire.");
System.out.println("\nThe current age and desired retirement age for Employee #8 is: " + (ages[7][0]) + " and " + (ages[7][1]) + ".");
System.out.println("Employee #8 has to work " + (employee8) + " years before they can retire.");
}
}
は今、私が把握しようとしていることですが、それだけに持っている場合、私は私ができるのかはわかりませんかスペースを取る。いずれにしても問題はありませんが、もう少し合理化されて見えるようにしたいと思います。助けてくれてありがとう!
javascriptではなく、javaのように見えます。 –
正直言って、私は彼らの違いを知らなかった。私は日食を使用しています、それはおそらくJavaとjavascript、申し訳ありません。 – senpaimaster
これは奇妙なことです:あなたは年齢のためにtwodim配列を使っても問題ありません...しかし、従業員のために配列を使用することはありません。代わりにコードを8回書くのに問題はありませんか? – GhostCat