zoukankan      html  css  js  c++  java
  • Java作业十三(2017-11-20)

    /*使用一位数组解决 1 1 2 3 5 8 13 数列问题 斐波纳契数列 Fibonacci*/
    package cn.GM;
    
    public class array {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		int arr[] = new int[30];
    		arr[0] = 1;
    		arr[1] = 1;
    		for (int i = 2; i < arr.length; i++) {
    			arr[i] = arr[i - 1] + arr[i - 2];
    			System.out.println(arr[i]);
    		}
    
    	}
    }
    

      

    /* 选择法。从小到大排列 */
    package cn.GM;
    
    public class yiwei {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		int[] arr = { 10, 347, 657, 38, 382, 75, 76, 56, 12344, 84654 };
    		/* 选择法。从小到大排列 */
    		for (int i = 0; i < arr.length - 1; i++) {
    			for (int j = i + 1; j < arr.length; j++) {
    				if (arr[i] > arr[j]) {
    					int temp = arr[i];
    					arr[i] = arr[j];
    					arr[j] = temp;
    				}
    			}
    
    		}
    		for (int i : arr)
    			System.out.println(i);
    	}
    
    }
    

      

    /*冒泡法。从小到大排列*/
    package cn.GM;
    
    public class yiwweiM {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		int[] arr = {10, 347, 657, 38, 382, 75, 76, 56, 12344, 84654};
    		/*冒泡法。从小到大排列*/
            for(int i = 0;i < arr.length;i++) {
                for(int j = 0;j < arr.length - 1 -i;j++) {
                    if(arr[j] > arr[j + 1]) {
                        int temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
    
            }
            for(int i : arr)
                System.out.println(i);
     
    	}
    
    }
    

      

    /*人类对象数组——一堆人*/
    package cn.GM;
    
    public class personarr {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		//建数组
    		person arr[] = new person[3];
    		arr[0] = new person("赵艺",20);
    		arr[1] = new person("欧阳娜娜",17);
    		arr[2] = new person("房祖名",32);
            for(int x = 0;x < arr.length;x++)
            	arr[x].getInfo();
        }
    
    }
    
    class person{
        private String name;
        private int age;
        public person(String name,int age) {
            this.name = name;
            this.age = age;
        }
        public void getInfo() {
            System.out.println("姓名:" + this.name + " 年龄:" + this.age);
    
    }
    
    	
    
    }
    

      

  • 相关阅读:
    Windows netstat
    LOIC Download
    Open CV 环境配置
    C++ strcat_s
    c++ strlen() 函数
    css实现1px 像素线条_解决移动端1px线条的显示方式
    css中line-height的理解_介绍line-height实际应用
    css 分割线样式_css实现文章分割线的多种方法总结
    css获取除第一个之外的子元素
    css实现div多边框_box-shadow模拟多边框、outline描边实现
  • 原文地址:https://www.cnblogs.com/chengxuyuanGM/p/7875651.html
Copyright © 2011-2022 走看看