|
|
|
Java คำนวณเกรด ช่วยเขียนโปรแกรมคำนวณเกรดด้วย Java - array ให้ศึกษาหน่อยครับ |
|
|
|
|
|
|
|
Code (Java)
package com.java.myapp;
public class MyClass {
public static void main(String[] args) {
int testscore = 76;
char grade;
if (testscore >= 90) {
grade = 'A';
} else if (testscore >= 80) {
grade = 'B';
} else if (testscore >= 70) {
grade = 'C';
} else if (testscore >= 60) {
grade = 'D';
} else {
grade = 'F';
}
System.out.println("Grade = " + grade);
}
}
Java if...else if...else
|
|
|
|
|
Date :
2013-08-31 13:01:27 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Main {
public static void main(String[] args) {
int[] Score = { 50, 55, 60, 65, 70, 75, 80, 85, 90, 95 };
System.out.println("Highest score : " + findMaxInArray(Score));
myMethod(Score);
}
public static void myMethod(int[] Score) {
String grade;
for (int i = 0; i <= 9; i++) {
if (Score[i] >= 90) {
grade = "A";
} else if (Score[i] >= 85) {
grade = "B+";
} else if (Score[i] >= 80) {
grade = "B";
} else if (Score[i] >= 75) {
grade = "C+";
} else if (Score[i] >= 70) {
grade = "C";
} else if (Score[i] >= 65) {
grade = "D+";
} else if (Score[i] >= 60) {
grade = "D";
} else {
grade = "F";
}
System.out.println("[ " + (i + 1) + " ] " + "Grade " + "(" + (Score[i]) + ")" + " = " + grade);
}
}
static int findMaxInArray(int[] arr) {
int MaxValue = arr[0];
for (int i = 0; i < arr.length; i++) {
if (arr[i] > MaxValue) {
MaxValue = arr[i];
}
}
return MaxValue;
}
}
|
|
|
|
|
Date :
2022-01-27 20:46:11 |
By :
PenGuin |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|