Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AuroraNorthernQuarter/d7581504171559e521183af86719d1a9 to your computer and use it in GitHub Desktop.
Save AuroraNorthernQuarter/d7581504171559e521183af86719d1a9 to your computer and use it in GitHub Desktop.
サンプルコード4
package testprogramm;
import java.util.Scanner;
public class Sample {
static void Disp(String[] name, double[] height) {
int n = name.length;
double sum = 0;
for (int i = 0; i < n; i++) {
System.out.println(name[i]);
for (int j = 0; j < n; j++) {
if (i == j)
continue;
System.out.println(height[j] + "cm");
}
sum = sum + height[i];
}
System.out.println("平均:" + sum / n + "cm");
}
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
while (true) {
System.out.print("得点を入力してください: ");
// キーボードから整数の入力を受け取る
int score = scan.nextInt();
if (score > 90) {
System.out.println("おめでとう! 合格です");
String name[] = new String[3];
double height[] = new double[3];
name[0] = "鈴木";
name[1] = "杉山";
name[2] = "田中";
height[0] = 168.7;
height[1] = 173.4;
height[2] = 155.8;
Disp(name, height);
break;
} else if (score >= 60) {
System.out.println("もう少し頑張りましょう。");
String name[] = new String[3];
double height[] = new double[3];
name[0] = "橋本";
name[1] = "高杉";
name[2] = "佐藤";
height[0] = 166.3;
height[1] = 159.1;
height[2] = 177.4;
Disp(name, height);
break;
} else if (score < 0) {
break;
}
}
scan.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment