3.输出,输入,基本数据类型

1.输出

package com.example;

public class MyClass {
    public  static void main(String args[]){
        System.out.println(Byte.MIN_VALUE + "~" + Byte.MAX_VALUE);

        System.out.println(Integer.parseInt("1000"));
        System.out.println(Integer.toBinaryString(100));
        System.out.println(Integer.toHexString(100));
        System.out.println(Integer.toString(200));
    }
}

 2.输入

package com.example;

import java.util.Scanner;

public class MyClass {
    public static void main(String[] args){
        //scanner从控制台输入数据
        Scanner scanner = new Scanner(System.in);

        System.out.println("姓名:");
        String name = scanner.next();

        System.out.println("性别:");
        char sex = scanner.next().charAt(0);

        System.out.println("年龄:");
        int age = scanner.nextInt();

        System.out.println("身高");
        double height = scanner.nextDouble();

        System.out.print("性格");
        String type = scanner.next();

        System.out.println("嗨,大家好,我是:"+name+",性别:"+sex+",年龄:"+age+",身高:"+height+",性格:"+type);
小雨,女,22,1.62,哈哈

       
    }
}

 3.基本数据类型及其转换

package com.example;

public class MyClass {
    public  static  void  main(String[] args){
        //1.
        long longValue = 3000000000l;
        //2.
        //自动转:byte->short->int->long
        //强转:long->ing->short->byte
        //3.
        byte b1 = 5;
        //因为一个整形数在内部存储为int
        //所以 byte b3 = b1 + 3是错的,可改成以下两种形式:
        byte b2 = (byte)(b1 + 3);
        int b3 = b1 + 3;


        //1.
        float c = 4.3f;
        //2.
        //自动转:float->double
        //强转:double->float

        //char类型:字符,汉字,英文字母,由''阔起来

        //BOOL类型:TRUE和FALSE
    }
}

 

posted @ 2017-01-07 08:57  894316728  阅读(212)  评论(0编辑  收藏  举报