编写程序,提示用户输入学生的数量及每个学生的名字和得分,而后显示最高分的学生?不用数组和方法怎么做到?import javax.swing.JOptionPane;
public class j {
public static void main(String[] args) {
String a = JOptionPane.showInputDialog(null,"请输入学生的数量");
int d = Integer.parseInt(a);
for(int i = 1; i <= d; i++){
String k = JOptionPane.showInputDialog(null,"请输入第"+i+"位学生的成绩");
//下面我不知道怎么写了。
}
}}
public class j {
public static void main(String[] args) {
String a = JOptionPane.showInputDialog(null,"请输入学生的数量");
int d = Integer.parseInt(a);
for(int i = 1; i <= d; i++){
String k = JOptionPane.showInputDialog(null,"请输入第"+i+"位学生的成绩");
//下面我不知道怎么写了。
}
}}
{
String a = JOptionPane.showInputDialog(null,"请输入学生的数量");
int d = Integer.parseInt(a);
int max=Integer.MIN_VALUE;
int maxIndex =-1;
int temp=0;
for(int i = 1; i <= d; i++){
String k = JOptionPane.showInputDialog(null,"请输入第"+i+"位学生的成绩");
temp =Integer.valueOf(k);
if(temp>max){
max=temp;
maxIndex=i;
}
}
JOptionPane.showMessageDialog(null, "第"+ maxIndex+"位学生的成绩最高,成绩是:"+max);
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/package exp1;/**
*
* @author szhu5
*/
import javax.swing.JOptionPane;
public class j {
public static void main(String[] args)
{
String a=JOptionPane.showInputDialog(null, "请输入学生的数量 ");
int d=Integer.parseInt(a);
int max=Integer.MIN_VALUE;
int maxIndex=-1;
int temp=0;
for(int i=1;i<=d;i++)
{
String k=JOptionPane.showInputDialog(null, "请输入第 "+i+ "位学生的成绩 ");
String f=JOptionPane.showInputDialog(null, "请输入第 "+i+ "位学生的姓名");
temp =Integer.valueOf(k);
if(temp> max)
{
max=temp;
maxIndex=i;
}
}
JOptionPane.showMessageDialog(null,"第 "+maxIndex+ "位学生的成绩最高,成绩是:"+max);
}
}
public static void main(String[] args) {
String a = JOptionPane.showInputDialog(null, "请输入学生的数量 ");
int d = Integer.parseInt(a);
int max = Integer.MIN_VALUE;
int maxIndex = -1;
String maxName = "";
int temp = 0;
for (int i = 1; i <= d; i++) {
String name = JOptionPane.showInputDialog(null, "请输入第 " + i
+ "位学生的名字 ");
String k = JOptionPane.showInputDialog(null, "请输入第 " + i
+ "位学生的成绩 ");
temp = Integer.valueOf(k);
if (temp > max) {
max = temp;
maxIndex = i;
maxName = name;
}
}
JOptionPane.showMessageDialog(null, "第 " + maxIndex + "位学生("+maxName+")的成绩最高,成绩是: "
+ max);
}有名字的加上数字校验就可以了
import java.util.Scanner;
public class showSname { /**
* @param args
*/
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("请输入学生数量:");
int num=input.nextInt();
String maxName="";
float maxScore=0;
for(int i=0;i<num;i++)
{
System.out.println("\n请输入第个"+(i+1)+"学生的姓名:");
String sName=input.next();
System.out.print("成绩:");
float sScore=input.nextFloat();
if(maxScore<sScore)
{
maxScore=sScore;
maxName=sName;
}
}
System.out.println("\n最高分的学生姓名为:"+maxName+",成绩为:"+maxScore);
}}
运行结果:请输入学生数量:
3请输入第个1学生的姓名:
张三
成绩:65请输入第个2学生的姓名:
李四
成绩:56请输入第个3学生的姓名:
王五
成绩:95最高分的学生姓名为:王五,成绩为:95.0