public class test {
static int s
public static void main(String[] argv) {
int [] num=new int[20]
Scanner scanner=new Scanner(System.in)
Integer a
int i
for(i=1i<=20i++){
System.out.println("请输入第"+i+"一个分数(结束请输入520嘿嘿):")
a=scanner.nextInt()
num[i-1]=a
if(a==520){
break
}
}
for(int m=0m<i-1m++)
{
s=s+num[m]
}
System.out.println("总共录入辩衡了"+(i-1)+"个分芹滚数")
System.out.println("总成绩是"+s+"分")
System.out.println("平均分是"+s/(i-1)+"分")
for(Integer m=0m<num.length-1m++)
{ if(num[m]>0&&num[m]!=520){
if(num[m]>=90)
System.out.println(num[m]+"优秀")
else if(num[m]>=80)
System.out.println(num[m]+"良好")
else if(num[m]>=70)
System.out.println(num[m]+"中等")
else if(num[m]>=60)
System.out.println(num[m]+"及格"携首做)
else
System.out.println(num[m]+"不及格")
}else break
}
}
}
我的代码很简洁,采纳我呗。。。
每输入一个数字判断一次
import java.util.Scannerpublic class Test {
public static void 余团main(String args[]) {
Scanner in = new Scanner(System.in)
int cj, yxsum = 0, tgsum = 渣毁薯0, bjgsum = 0
while ((cj = in.nextInt()) != 如者0) {
if (cj >= 85) {
yxsum++
} else if (cj >= 60) {
tgsum++
} else {
bjgsum++
}
}
System.out.println(yxsum)
System.out.println(tgsum)
System.out.println(bjgsum)
}
}
import java.util.ArrayListimport java.util.Collections
import java.util.Comparator
import java.util.HashMap
import java.util.List
import java.util.Map
import java.util.Map.Entry
public class MapSort {
public static void main(String[] args) {
String str = "adf adf ad adf adf ad ad f ad ad"
String[] items = str.split(" ")
Map<String, Integer>map = new HashMap<String, Integer>贺槐()
for (String s : items) {
if (map.containsKey(s))
map.put(s, map.get(s) + 1)
else {
map.put(s, 1)
}
}
List<Entry<String, Integer>>list = new ArrayList<Entry<String, Integer>>()
for (Entry<String, Integer>entry : map.entrySet()) {
list.add(entry)
}
Collections.sort(list, new EntryComparator())
for (Entry<String, Integer>obj : list) {
System.out.println(obj.getKey() + "\t" + obj.getValue())
}
}
}
class EntryComparator implements Comparator<Entry<String, Integer>>档粗 {
public int compare(Entry<String, Integer>o1, Entry<String, Integer>o2) {
return o1.getValue() >o2.getValue() ? 0 : 1
}
}
参数你可以自己修行拍镇改!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)