Random method
Posted resort-033
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Random method相关的知识,希望对你有一定的参考价值。
output:1~10
import java.util.Random; public class Random_test { public static void main(String[] args){ Random r=new Random(); int num; num=r.nextInt(10); System.out.println(num+1); } }
2.gambling numbers
package Gambling_numbers; import java.util.Random; import java.util.Scanner; public class 赌数字 { public static void main(String [] args){ Random r=new Random(); int num1=r.nextInt(15); System.out.println("Start gambling!"); Scanner sc=new Scanner(System.in); int num2=sc.nextInt(); if(num1<5) { System.out.println("smaller than 5"); }else if(num1>=5&&num1<10){ System.out.println("smaller than 10 and bigger than 5"); }else{ System.out.println("else"); } while(num1!=num2){ System.out.println("false"); System.out.println("next"); int num3=sc.nextInt(); num2=num3; } if(num1==num2){ System.out.println("bingo"); } } }
3.example
以上是关于Random method的主要内容,如果未能解决你的问题,请参考以下文章