• 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
        }
    }
    
  • 相关阅读:
    Marriage Match II 【HDU
    Leapin' Lizards [HDU
    稳定婚姻匹配问题
    Sabotage 【UVA
    动态树 学习
    Minimum Cost 【POJ
    Colourful Rectangle【扫描线】
    Get The Treasury【HDU-3642】【扫描线】
    Picture【HDU
    洛谷P1457 城堡 The Castle
  • 原文地址:https://www.cnblogs.com/BelieveFish/p/6258667.html
Copyright © 2020-2023  润新知