java - Random18
猜数字案例
package com.demo.test; import java.util.Random; import java.util.Scanner; public class rr { public static void main(String[] args) { r(); } public static void r() { Scanner sc = new Scanner(System.in); Random r = new Random(); int num = r.nextInt(100); while (true){ int num2 = sc.nextInt(); if (num > num2){ System.out.println("您猜小了"); }else if (num < num2){ System.out.println("您猜大了"); }else { System.out.println("您猜对了"); break; } } } }
代码改变了我们,也改变了世界