zoukankan      html  css  js  c++  java
  • java-学习6

    public class arryTest4 {
        //对整型数组按照由小到大的顺序进行排序
        public static void main(String[] args) {
            int score[]= {67,89,87,69,90,100,75,90};
            for(int i=1;i<score.length;i++) {
                for(int j=0;j<score.length;j++) {
                    if(score[i]<score[j]) {
                        int temp = score[i];
                        score[i] = score[j];
                        score[j] = temp;
                    }
                }
            }
            for (int i=0;i<score.length;i++) {
                System.out.println(score[i]+"	");
            }
        }
    }
    Scanner sc=new Scanner(System.in);
    
     
    
    意思是:通过new Scanner(System.in)创建一个Scanner,控制台会一直等待输入,直到敲回车键结束,把所输入的内容传给Scanner,作为扫描对象。
    
    要获取输入的内容,则只需要调用Scanner的nextLine()方法
    
    举例:
    
     
    
    public class TestScanner { 
            public static void main(String[] args) { //定义main方法
                    Scanner s = new Scanner(System.in); //定义scanner,等待输入
                    System.out.println("请输入字符串:"); 
                    while (true) { 
                            String line = s.nextLine(); //读取输入内容
                            if (line.equals("exit")) break; //如果读取到exit,则退出输入
                            System.out.println(">>>" + line); //打印输入内容
                    } 
            } 
     
    }
    public class arryTest3 {
        public static void main(String[] args) {
            int score[] = {67,89,87, 69,90,100,75,90};
            int max=0;
            int min=0;
            max=min=score[0];
            
            for(int x=0;x<score.length;x++) {
                if(score[x]>max) {
                    max=score[x];
                }
                if(score[x]<min) {
                    min=score[x];
                }
            }
                System.out.println("最高成绩:"+max);
                System.out.println("最低成绩:"+min);
            }
            
    }
    public class arryTest {
        
        public static void main(String[] args) {
            //学生成绩管理系统
            int student;//控制学生的变量
            double sum=0,avg=0;//总成绩和平均成绩
            double[] temp=new double[10];
            //创建一个Scanner类的对象,用它来获得用户的输入
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入前10名的成绩");
        
            for(student=0;student<temp.length;student++) {
                //读取用户的输入
                temp[student]=sc.nextDouble();
                sum+=temp[student];
            }
            
            avg=sum/10;
            
            System.out.println("平均值是:"+avg);
            
            for(student=0;student<temp.length;student++) {
                
                if(temp[student]<avg) {
                    System.out.println(temp[student]+"该学生的成绩低于平均成绩");
                    
                }else if(temp[student]>avg) {
                    System.out.println(temp[student]+"该学生的成绩高于平均成绩");
                    
                }else {
                    System.out.println(temp[student]+"该学生的成绩等于平均成绩");
                    
                }
            }
            
            
        }
    }
    public class TestArr {
        public static void main(String[] args) {
            //声明数组
            double array1[];
            double[] array2;
            double[] array3,array4,array5;
            //分配内存空间
            array1=new double[5];
            array1[0]=0;
            array1[1]=1;
            array1[2]=3;
            array1[3]=23;
            System.out.println(array1[3]);
        }
    }
    public class testWhile {
        public static void main(String[] args) {
            int i=1;
            while(i<=10) {//括号里写true变成死循环
                System.out.println("while第"+i+"次循环");
                i++;
            }
        }
    }
  • 相关阅读:
    共享无法访问问题,通过ip地址或者主机名无法访问目的主机
    开机系统更新,一直停在?%处,无法进入系统
    win7电脑访问内网地址报错0x800704cf,0x80070035解决方法
    电脑共享--问题汇总
    win10域账户用户时间无法和域服务器同步
    卸载WPS后,原office出现各种问题,报错,图标混乱
    局域网新装电脑主机网络断断连连解决方案
    win10主机无法进入本地共享,“没有权限”
    win10安装部分软件报错“应用程序无法启动,应用程序并行配置不正确,或使用命令行sxstrace.exe”
    【日常修机】打印机故障维护
  • 原文地址:https://www.cnblogs.com/liaohongwei/p/9876212.html
Copyright © 2011-2022 走看看