代码改变世界

java中引用数据类型Scanner类和Random类的使用-0509

2018-05-14 10:52  yelena  阅读(154)  评论(0编辑  收藏  举报
import java.util.Scanner;
class Demo02 
{
    public static void main(String[] args) 
    {
        //导包
        //创建该类对象
        Scanner sc = new Scanner(System.in);
        //用该对象调用类里面的方法
        //int i = sc.nextInt();
        //String str = sc.next();
        Double i = sc.nextDouble();
        System.out.println("你输入的内容为:"+i);
    }
}
import java.util.Scanner;
class Demo04 
{
    public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in);
        /*int num = sc.nextInt();
        if(num%2==0){
           System.out.println("偶数");
        }else{
           System.out.println("奇数");
        }
        if(num<60){
           System.out.println("不及格");
        }else if(num<=70){
           System.out.println("良好");
        }else if(num<=80){
           System.out.println("中等");
        }else{
           System.out.println("优秀");
        }*/
        System.out.println("请输入");
        int a = sc.nextInt();
        System.out.println("请再次输入");
        int b = sc.nextInt();
        int max = 0;
        max = a>b?a:b;
        System.out.println("最大值为:"+max);
    }
}
import java.util.Random;
class Demo03 
{
    public static void main(String[] args) 
    {
        //导包
        //创建对象
        Random r = new Random();
        //调用方法,并定义一个变量去接收
        int sjs = r.nextInt(10);
        double sjxs = r.nextDouble();
        System.out.println(sjs);
        System.out.println(sjxs);
    }
}
import java.util.Random;
class dianming 
{
    public static void main(String[] args) 
    {
        Random r = new Random();
        int sz = r.nextInt(8);
        if(sz==0){
            System.out.println("董斌");
    }
         else if(sz==1){
             System.out.println("张锐");
     }
         else if(sz==2){
              System.out.println("王荣臣");
         }
         else if(sz==3){
              System.out.println("韩凯");
         }
         else if(sz==4){
               System.out.println("张禄");    
                   }
         else if(sz==5){
               System.out.println("刘继勋");
         }
         else if(sz==6){
               System.out.println("张维");
         }
         else{
               System.out.println("魏子豪");
         }
         }
         }
import java.util.Random;
class szdianming 
{
    public static void main(String[] args) 
    {
        Random r = new Random();
        int i = r.nextInt(8);
        String[] arr = {"董斌","张锐","王荣臣","韩凯","张禄","刘继勋","张维","魏子豪"};
        System.out.println(arr[i]);
    }
}