第三周作业

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. //判断是否为闰年。  
  2.   
  3. import javax.swing.JOptionPane;    
  4.   
  5. public class LeapYear    
  6. {    
  7.     public static void main(String args[])    
  8.     {    
  9.         int year = Integer.parseInt(JOptionPane.showInputDialog(null,"请输入一个年份"));    
  10.         if((year % 4 == 0 && year % 100 != 0) || (year % 4 == 0 && year % 400 == 0))    
  11.         {    
  12.             JOptionPane.showMessageDialog(null,year + " 年是闰年!");    
  13.         }         else    
  14.         {            JOptionPane.showMessageDialog(null,year + " 年不是闰年!");    
  15.         }    
  16.     }    
  17. }    


   

  

 

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. //图形界面学生签到程序。  
  2.   
  3. import java.awt.Button;    
  4. import java.awt.FlowLayout;    
  5. import java.awt.Frame;    
  6. import java.awt.Label;    
  7. import java.awt.TextArea;    
  8. import java.awt.TextField;    
  9. import java.awt.event.*;    
  10. import java.io.File;    
  11. import java.io.FileNotFoundException;    
  12. import java.io.PrintWriter;    
  13. import java.text.SimpleDateFormat;    
  14. import java.util.Date;    
  15. import java.util.Scanner;      
  16. import javax.swing.JFrame;     
  17. public  class RegisterDemo extends Frame implements ActionListener   
  18. {    
  19.     static String[][] stringArray ;   
  20.     static JFrame jf = new JFrame("GUI example");//JFrame容器    
  21.     static Label lb = new Label("学生姓名");    
  22.     static TextField tf = new TextField(10);    
  23.     static Button b1 = new Button("到");    
  24.     static Button b2 = new Button("缺席");    
  25.     static Label b = new Label("缺到名单");    
  26.     static TextArea ta = new TextArea(15,30);    
  27.     static int count2 = 0;//记录学生人数    
  28.     static int count = 0;//记录学生人数    
  29.     static String strAbsent = " ";//记录缺席的学生姓名    
  30.   
  31.     public static void main(String[] args) throws Exception {    
  32.         File fileinput=new File("E:\\wl121.txt");  //输入文件    
  33.         Scanner sc = new Scanner(fileinput);  //构造新的Scanner,指定fileinput为其生成值    
  34.         Scanner st = new Scanner(fileinput);  //同上    
  35.   
  36.         while (sc.hasNext()) //确定人数      
  37.         {    
  38.             count++;      
  39.             sc.nextLine();      
  40.         }    
  41.         stringArray = new String[count + 1][2];//给数组stringArray加多一位,后面用得上    
  42.         for (int a = 0; a < count ; a++)//读入数组      
  43.         {           
  44.             stringArray[a][0] = st .nextLine();    
  45.         }      
  46.         sc.close();     
  47.         st.close();    
  48.   
  49.         stringArray[count][0] = "点名结束";    
  50.         tf.setText(stringArray[count2][0]);//在文本框中加入数组的第一行内容    
  51.   
  52.         RegisterDemo tu = new RegisterDemo();//构造方法    
  53.   
  54.         jf.setLayout(new FlowLayout(FlowLayout.LEFT,20,40));//布局管理器    
  55.         jf.add(lb);    
  56.         jf.add(tf);    
  57.         jf.add(b1);    
  58.         jf.add(b2);    
  59.         jf.add(b);    
  60.         jf.add(ta);    
  61.         jf.setSize(350,450);//设定大小    
  62.         jf.setVisible(true);//容器可见    
  63.         b1.addActionListener(tu);//监听按钮    
  64.         b2.addActionListener(tu);//监听按钮    
  65.     }    
  66.     public  void actionPerformed(ActionEvent e)//监听事件    
  67.     {    
  68.   
  69.         if(e.getSource()==b1 && count2 < count)//点击“到”按钮并且总点击数少于人数时,往下执行  
  70.         {                 
  71.             count2++;                                             
  72.             tf.setText(stringArray[count2][0]);//在文本框中加入数组的内容    
  73.   
  74.         }    
  75.         else if(e.getSource()==b2 && count2 < count)//点击“缺席”按钮并且总点击数少于人数时,往下执行    
  76.         {    
  77.             strAbsent = strAbsent + stringArray[count2][0] + "\n";//把缺席的名字记录到strAbsent中    
  78.             count2++;//    
  79.             tf.setText(stringArray[count2][0]);//在文本框中加入数组的内容    
  80.         }    
  81.         if(count2 == count)//当读完了所有名字后,把缺席名单显示在文本域中    
  82.         {    
  83.             ta.setText(strAbsent);    
  84.             ta.getSelectedText();                  
  85.         }    
  86.         Date now = new Date();//获得当前日期,以便在每天考勤后自动生成不同名字的考勤结果文件    
  87.         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHMM");//方便修改日期格式      
  88.         String strDate = dateFormat.format(now);//把时间类型改为字符串    
  89.         File fileoutput = new File("E:\\wl121.txt"+"\\考勤结果" + strDate);    
  90.         PrintWriter output = null;//准备输出考勤结果    
  91.         try  
  92.         {    
  93.             output = new PrintWriter(fileoutput);//构造新的PrintWriter,指定fileoutput为其生成值    
  94.         }   
  95.         catch (FileNotFoundException e1)   
  96.         {    
  97.         }  
  98.         if(count2 == count)    
  99.         {    
  100.             output.print("缺课名单: ");    
  101.             output.print(strAbsent);//输出考勤结果    
  102.             output.close();    
  103.         }    
  104.     }    
  105. }           

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你好!改善深层神经网络的方法有很多,以下是一些常见的方法: 1. 使用更好的激活函数:传统的激活函数如Sigmoid、tanh等可能存在梯度消失或爆炸的问题。可以尝试使用ReLU、Leaky ReLU、ELU等激活函数,以减轻这些问题。 2. 使用批标准化(Batch Normalization):批标准化对网络的输入进行标准化,有助于加快网络的训练速度,并且可以缓解梯度问题,使得更深层的网络也能够训练得更好。 3. 使用残差连接(Residual Connections):残差连接可以帮助信息在网络更好地流动,从而减轻梯度消失的问题。通过将某些层的输出与输入相加,可以使得网络更易于训练。 4. 使用更好的优化算法:传统的梯度下降算法如随机梯度下降(SGD)可能存在训练速度慢、易陷入局部最优等问题。可以尝试使用更高级的优化算法如Adam、RMSprop等,以加快模型的收敛速度。 5. 添加正则化:过拟合是深层神经网络常见的问题之一。可以通过添加正则化项如L1正则化、L2正则化等来限制模型的复杂度,防止过拟合的发生。 6. 数据增强:通过对训练数据进行一些随机的变换,如平移、旋转、缩放等,可以增加模型的泛化能力,防止过拟合。 这些方法只是改善深层神经网络的一部分,具体的选择和调整需要根据具体问题和数据集来进行。希望对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值