举例

1、输入五个学生的姓名和成绩,输出成绩单,并且显示哪些学生不及格。

import javax.swing.JOptionPane;


public class chengji {


public static void main(String[] args) {
String[] nameArray = new String[5];
int[] scoreArray = new int[5];
for (int i = 0; i < nameArray.length; i++) {
String name = JOptionPane.showInputDialog(null, "请输入第" + (i + 1)
+ "个学生的姓名");
String s = JOptionPane.showInputDialog(null, "请输入第" + (i + 1)
+ "个学生的成绩");
nameArray[i] = name;
scoreArray[i] = Integer.parseInt(s);


}
String str = "姓名        成绩\n";
String name = "不及格";
for (int i = 0; i < nameArray.length; i++) {
str += nameArray[i] + "    " + scoreArray[i] + "\n";
if (scoreArray[i] < 60) {
name += nameArray[i] + "";
}
}
JOptionPane.showMessageDialog(null, str + name);


}
}



2、输入五个员工的姓名和工资。显示工资最高的员工信息。

import javax.swing.JOptionPane;


public class gongzi {


public static void main(String[] args) {
String[] nameArray = new String[5];
int[] moneyArray = new int[5];
for (int i = 0; i < nameArray.length; i++) {
String me = JOptionPane.showInputDialog(null, "请输入第" + (i + 1)
+ "个人的姓名");
String s = JOptionPane.showInputDialog(null, "请输入第" + (i + 1)
+ "个人的工资");
nameArray[i] = me;
moneyArray[i] = Integer.parseInt(s);


}
String str = "姓名        工资\n";
for (int i = 0; i < nameArray.length; i++) {
str += nameArray[i] + "    " + moneyArray[i] + "\n";
}


int me = 1;
int b = -1;
for (int i = 0; i < moneyArray.length; i++) {
if (me < moneyArray[i]) {
me = moneyArray[i];
b = i;


}
}
JOptionPane.showMessageDialog(null, str + "最高工资的员工为:" + nameArray[b]
+ ",其工资为:" + moneyArray[b]);
}


}





3、输入五个数字,从大到小排列显示。


import javax.swing.JOptionPane;


public class paixu {


public static void main(String[] args) {
int[] a = new int[5];
for (int i = 0; i < a.length; i++) {
String x = JOptionPane.showInputDialog(null, "请输入第" + (i + 1)
+ "个数");
a[i] = Integer.parseInt(x);
}
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++) {
if (a[i] < a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;


}
}
}
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
}







你可能感兴趣的:(举例)