java删除成绩代码 java删除代码怎么写( 二 )


}
}
如何用java编写一个,手动输入10个分数,去掉一个最高分,去掉一个最低分,并把剩余的数求平均值的的输出结果图:
参考代码如下:
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class xxx {
public static void main(String[] args) {
System.out.println("请输入10个数字,以逗号隔开:");
Scanner scanner=new Scanner(System.in);
String input=scanner.next();
//将输入的数字按照","分割成数组
String[] numStrs=input.split(",");
ListInteger nums=new ArrayListInteger();
//将数组的数字放入集合list中方便排序和取出最大最小数
for (int i = 0; inumStrs.length; i++) {
nums.add(Integer.parseInt(numStrs[i]));
}
Collections.sort(nums);
System.out.println("从小往大排序后:"+nums);
nums.remove(0);
nums.remove(nums.size()-1);
System.out.println("去掉最小数和最大数后:"+nums);
double avg=0d;
int sum=0;
//求出剩下数字的总和
for (int i = 0; inums.size(); i++) {
sum+=nums.get(i);
}
//求平均值(总和/剩下数字的个数)
avg=sum/(nums.size());
System.out.println("["+nums+"]的平均数为:"+avg);
}
}
学生管理系统的删除学生信息 删除代码请修改一下 。。急需帮助 。。马上就要交作业了import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DeleteFrame extends JFrame implements ActionListener {
private MainFrame parentF;
JTextField jt1=new JTextField();
JTextField jt2=new JTextField();
JTextField JTextField_free=new JTextField();
JButton jb=new JButton("删除");
JOptionPane JOptionPane1 = new JOptionPane();
public DeleteFrame(MainFrame m){
super("删除学生信息 ");
parentF=m;
this.setSize( 400,250);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Container c=this.getContentPane();
c.setLayout(null);
JLabel j1=new JLabel("学号");
JLabel j2=new JLabel("姓名");
c.add(j1);
j1.setBounds(10,10,60,30);
c.add(jt1);
jt1.setBounds(70,10,100,30);
c.add(j2);
j2.setBounds(200,10,60,30);
c.add(jt2);
jt2.setBounds(250,10,100,30);
c.add(jb);
jb.setBounds(100,180,60,40);
jb.addActionListener(this);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
parentF.setVisible(true);
shutDown();
}
});
}
public void shutDown(){
this.dispose();
}
public void deleteRecord(int id){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
System.exit(-1);
}
try{
String URL="jdbc:odbc:student1";
Connection con =DriverManager.getConnection(URL);
Statement stmt1=con.createStatement();
String SQL="delete from 成绩表 where id = " + id;
ResultSet rs=stmt1.executeQuery(SQL);
System.out.println(stmt1);
stmt1.close();
con.close();
JTextField_free.setText("");
JOptionPane1.showMessageDialog(this,"删除成功","消息",
JOptionPane.INFORMATION_MESSAGE);
}
catch(SQLException ex){
ex.printStackTrace();
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jb){
this.deleteRecord(id);//id为所删记录的主键值
}
}
}
基于java设计一个学生成绩管理系统,要求有界面,且有增加,查询,修改,删除 , 退出功能,代码如何写?import java.awt.Color;

推荐阅读