• JAVA之数组


    /**
     * 功能:数组的定义
     */
    package com.test;

    import java.io.BufferedReader;
    import java.io.InputStreamReader;

    public class test6 {

        /**
         * @param args
         */
        public static void main(String[] args) throws Exception{
            // TODO Auto-generated method stub
            
            //简单数组

            int[] xx = new int[5];
            
            int[] yy = {1,2,3,4,5,6,7,8,9};
            
            int[] zz = {};
            
            System.out.println(xx[4]);
            
            System.out.println(xx.length);
            
            System.out.println(yy[4]);
            
            System.out.println(zz.length);
            
            //对象数组
            
            Ox[] ox = new Ox[4];
            
            //给每头牛赋初值
            
            //建立输入通道
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            
            //从控制台读取数据
            for(int i=0; i<ox.length; i++)
            {
                ox[i] = new Ox();
                System.out.println("输入牛牛的名字:");
                ox[i].setName(String.valueOf(br.readLine()));    
                System.out.println("输入牛牛的体重:");
                ox[i].setWeight(Integer.valueOf(br.readLine()));
            }
            
            //打印每头牛的信息
            for(int j=0; j<ox.length; j++)
            {
                System.out.println(ox[j].getName());
                System.out.println(ox[j].getWeight());
            }
                
        }

    }

    //定义一个牛类
    class Ox
    {
        private String name;
        private int weight ;
        
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getWeight() {
            return weight;
        }
        public void setWeight(int weight) {
            this.weight = weight;
        }
        
    }
    小结:

  • 相关阅读:
    html5不能播放视频的方法
    mysql找出重复数据的方法
    jquery each循环遍历完再执行的方法
    Android:TextView跑马灯-详解
    日志处理(一) log4j 入门和详解(转)
    周记 2014.11.08
    周记 2014.11.01
    linux下解压命令大全
    关于Context []startup failed due to previous errors
    周记 2014.10.25
  • 原文地址:https://www.cnblogs.com/milantgh/p/4037388.html
Copyright © 2020-2023  润新知