JAVA笔记1__基本数据类型/输入输出/随机数/数组

本文介绍了Java中的八种基本数据类型,包括boolean、byte、short等,并通过示例展示了long、float和double类型的使用。此外,文章还讲解了数组的四种定义方式及如何获取数组长度。
/**八种基本数据类型
        boolean
        byte
        short
        int
        long
        char
        float
        double
*/
public class test1{
    public static void main(String[] args){
        long g = 1000L;
        float f = 3.14F;
        double d = 10.12345d;
    }
}

 

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        System.out.println("a+b = "+(a+b));
    }
}

 

import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        /**
         * 数组三种方式:
         * int x[]; //先声明
         * 2.int[] x = new int[3];
         * 3.int[] x = new int[]{3,4,5};
         * 4.int[] x = {1,2,3,4};
         * 求数组长度:x.length
         */
        Random r = new Random();
        //返回一个伪随机数,它是取自此随机数生成器序列的、在 0(包括)和指定值(不包括)之间均匀分布的 int 值。
        int x = r.nextInt(10);
        System.out.println(x);
    }
}

 

转载于:https://www.cnblogs.com/fish7/p/4135971.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值