Java期末课程学习汇总。

本学期面向对象与Java程序设计课程已经结束了,给自己学习来个总结。

本学期过的非常快,不得不说这一学期学到的东西很少,感觉自己的进步很小。

而且感觉自己总少了点什么,在写这篇总结前,我认真想了,很多时间浪费了。

有的时候甚至不知道自己在干嘛,,每当要写总结的时候,又没怎么学习。

希望自己不要再浪费时间了,可以在大学学会更多的知识,成为那个最好的自己。

每周总结汇总:

第一次:https://www.cnblogs.com/tengziqiang/p/11479629.html

第三周:https://www.cnblogs.com/tengziqiang/p/11517220.html

第四周:https://www.cnblogs.com/tengziqiang/p/11559090.html

第五周:https://www.cnblogs.com/tengziqiang/p/11598257.html

第六周:https://www.cnblogs.com/tengziqiang/p/11630368.html

第七周:https://www.cnblogs.com/tengziqiang/p/11655177.html

第八周:https://www.cnblogs.com/tengziqiang/p/11698660.html

第九周:https://www.cnblogs.com/tengziqiang/p/11737914.html

第十周:https://www.cnblogs.com/tengziqiang/p/11777784.html

十一周:https://www.cnblogs.com/tengziqiang/p/11820028.html

十二周:https://www.cnblogs.com/tengziqiang/p/11872325.html

十三周:https://www.cnblogs.com/tengziqiang/p/11917376.html

十四周: https://www.cnblogs.com/tengziqiang/p/11958306.html

写过的代码节选:

记事本:

代码:

package dome1;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;
public   class JKQ implements ActionListener {

    JFrame frame;
    JMenuBar bar;
    JMenu fileMenu,editMenu;
    JMenuItem newItem,openItem,saveItem,closeItem;
    ImageIcon newIcon,openIcon,saveIcon,closeIcon;
    JScrollPane scorll;
    JTextArea area;
    File file;
    private JFileChooser chooser;
    
    public  JKQ(){
        frame = new JFrame("小本本");
        bar = new JMenuBar();
        fileMenu = new JMenu("文件");
        editMenu = new JMenu("编辑");
        newItem = new JMenuItem("新建(N)",newIcon);
        openItem = new JMenuItem("打开(O)",openIcon);
        saveItem = new JMenuItem("另存为(A)",saveIcon);
        closeItem = new JMenuItem("关闭(X)",closeIcon);
        newIcon = new ImageIcon("d:"+File.separator+"新建.png");
        openIcon = new ImageIcon("D:"+File.separator+"打开.png");
        saveIcon = new ImageIcon("D:"+File.separator+"另存为.png");
        closeIcon = new ImageIcon("D:"+File.separator+"关闭.png");
        area = new JTextArea();
        scorll = new JScrollPane(area);
        
        newItem.setMnemonic(KeyEvent.VK_N);
        openItem.setMnemonic(KeyEvent.VK_O);
        saveItem.setMnemonic(KeyEvent.VK_A);
        closeItem.setMnemonic(KeyEvent.VK_X);
        
        fileMenu.add(newItem);
        fileMenu.add(openItem);
        fileMenu.add(saveItem);
        fileMenu.addSeparator();
        fileMenu.add(closeItem);
        
        newItem.addActionListener(this);
        openItem.addActionListener(this);
        saveItem.addActionListener(this);
        closeItem.addActionListener(this);
        
        bar.add(fileMenu);
        bar.add(editMenu);
        
        frame.setJMenuBar(bar);
        frame.add(scorll);
        frame.setSize(666, 333);
        frame.setVisible(true);
        
        
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        Object obj = e.getSource();
        if (obj instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) obj;
            if (item == newItem) {
                new JKQ();           
            }else if (item == openItem) {
                chooser = new JFileChooser();
                chooser.showOpenDialog(null);
                file = chooser.getSelectedFile();
            }
            
        }
        
    }
}
package dome1;

public class TEST {

    public static void main(String[] args) {

        new JKQ();

    }
}

实验代码:

package Java11;
    class MyThread implements Runnable{
            private int ticket = 1000;
            
            public void run() {
                for(int i = 0; i < 1000; i++) {
                       this.sale();
                       if(i == Math.sqrt(i) * Math.sqrt(i)) {
                           Thread.currentThread().yield();
                       }
                    }
                }
            
             public synchronized void sale() {
                    if(ticket > 0) {
                        try {
                            Thread.currentThread().sleep(1000);
                        }catch(InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println(Thread.currentThread().getName()+"卖票:ticket="+ticket--);
                    }
             }
    }
package Java11;

public class 测试类 {

    public static void main (String args[]) {
        MyThread my = new MyThread();
        Thread my1 = new Thread(my);
        my1.setName("窗口1");
        
        Thread my2 = new Thread(my);
        my2.setName("窗口2");
        
        Thread my3 = new Thread(my);
        my3.setName("窗口3");
        
        Thread my4 = new Thread(my);
        my4.setName("窗口4");
        
        Thread my5 = new Thread(my);
        my5.setName("窗口5");
        
        Thread my6 = new Thread(my);
        my6.setName("窗口6");
        
        Thread my7 = new Thread(my);
        my7.setName("窗口7");
        
        Thread my8 = new Thread(my);
        my8.setName("窗口8");
        
        Thread my9 = new Thread(my);
        my9.setName("窗口9");
        
        Thread my10 = new Thread(my);
        my10.setName("窗口10");
        
        my1.start();
        my2.start();
        my3.start();
        my4.start();
        my5.start();
        my6.start();
        my7.start();
        my8.start();
        my9.start();
        my10.start();
         
    }
}

水仙花数:

package dome2;

import java.util.Scanner;

public class shuixianhuashu {
public static void main (String[] args){
				Scanner sc =new Scanner(System.in);
		        int n=sc.nextInt();
		        int i,a,b,c,d,e,f,g;
		        if(n==3) {
		            for(i=100; i<=999;i++) {
		            	a=i/100;             //求第一个数
		            	b=(i%100)/10;		   //第二个数
		            	c=i%10;
		            	if(Math.pow(a, 3)+Math.pow(b, 3)+Math.pow(c, 3) == i) {
		            		System.out.println(i);
		            	}
		            }
		        }
		        
		        else if(n==4) {
		        	for(i=1000;i<=9999;i++) {
		        		a=i/1000;
		        		b=(i%1000)/100;
		        		c=(i%100)/10;     // 1234/100余34,34/10=3;
		        		d=i%10;
		        		if(Math.pow(a, 4)+Math.pow(b, 4)+Math.pow(c, 4)+Math.pow(d,4) == i) {
		        			System.out.println(i);
		        		}
		        	}
		        }
		        
		        else if(n==5) {
		        	for(i=10000;i<=99999;i++) {
		        		a=i/10000;
		        		b=(i%10000)/1000;
		        		c=(i%1000)/100;         // 12345/1000余345,345/100=3
		        		d=(i%100)/10;          // 12345/100=123余45;45/10=4
		        		e=i%10;
		        		if(Math.pow(a, 5)+Math.pow(b, 5)+Math.pow(c, 5)+Math.pow(d,5)+Math.pow(e, 5)== i) {
		        			System.out.println(i);
		        		}
		        	}
		        }
		        
		        else if(n==6) {
		        	for(i=100000;i<=999999;i++) {
		        		a=i/100000;
		        		b=(i%100000)/10000;
		        		c=(i%10000)/1000;          // 123456除以10000余3456,3456/1000=3;
		        		d=(i%1000)/100;            //123456除以1000余456.....
		        		e=(i%100)/10;
		        		f=i%10;
		        		if(Math.pow(a, 6)+Math.pow(b, 6)+Math.pow(c, 6)+Math.pow(d,6)+Math.pow(e, 6)+Math.pow(f, 6)== i) {
		        			System.out.println(i);
		        		}
		        	}
		        }
		        
		        else if(n==7) {
		        	for(i=1000000;i<=9999999;i++) {
		        		a=i/1000000;
		        		b=(i%1000000)/100000;
		        		c=(i%100000)/10000;          
		        		d=(i%10000)/1000;           
		        		e=(i%1000)/100;
		        		f=(i%100)/10;
		        		g=i%10;
		        		if(Math.pow(a, 7)+Math.pow(b, 7)+Math.pow(c, 7)+Math.pow(d,7)+Math.pow(e, 7)+Math.pow(f, 7)+Math.pow(g, 7)== i) {
		        			System.out.println(i);
		        		}
		        	}
		        }

		    }
		}

posted on 2019-12-13 22:27  Ttzp  阅读(373)  评论(0编辑  收藏  举报

导航