利用Random()產生1~100的隨機亂數
猜它到猜對為止!
herrDeng網內搜尋

自訂搜尋
Ads
訂閱:
張貼留言 (Atom)
熱門文章
-
請用CPU-Z軟體檢測Cache & Memory 註:快取(L1-L3: SRAM) 第一級快取(L1)–通常存取只需要幾個週期,通常是幾十個KB。 第二級快取(L2)–比L1約有2到10倍較高延遲性,通常是幾百個KB或更多。 第三級快取(L3)(不...
-
C++ DP速解難題leetcode 3363 Find the Maximum Number of Fruits Collected [Python解請進]
-
計算gcd(123456789,999999999)
-
需要練習的Java程式:
-
輸入字串s 輸入int x 輸出 x個s
-
Leetcode 342 Power of Four幾個C++一行解 [codes on Leetcode] https://leetcode.com/problems/power-of-four/solutions/7081839/9-ways-of-bit-manipula...
-
問int怎麼存-689這個數字。 int用4個bytes。 答案請用16進位表達。
15 則留言:
import java.util.Random;
import java.util.Scanner;
public class bb {
public static void main(String[]args){
Random ran = new Random();
int r=ran.nextInt(100)+1;
int x;
do{
Scanner sc =new Scanner(System.in);
System.out.println("請輸入值:");
x=sc.nextInt();
if(x==r)
System.out.println("猜對了!");
else if(x>r)
System.out.println("太大了!");
else
System.out.println("太小了!");
}while(x>=0);
}
}
import java.util.Random;
import java.util.Scanner;
public class bb {
public static void main(String[]args){
Random ran = new Random();
int r=ran.nextInt(100)+1;
int x;
do{
Scanner sc =new Scanner(System.in);
System.out.println("請輸入值:");
x=sc.nextInt();
if(x==r)
System.out.println("猜對了!");
else if(x>r)
System.out.println("太大了!");
else
System.out.println("太小了!");
}while(x>=0);
}
}
import java.util.Random;
import java.util.Scanner;
public class ex {
public static void main(String[] args) {
Random ran=new Random();
int r=ran.nextInt(100)+1;
long product = 1;
int x;
do{
Scanner sc=new Scanner(System.in);
System.out.println("請輸入值");
x=sc.nextInt();
if(x==r){
System.out.println("猜對了");
break;
}
else if(x>r)
System.out.println("太大了!");
else
System.out.println("太小了!");
}while(x>0 && x<100);
}
import java.util.Random;
import java.util.Scanner;
public class cxvbxcvbxvbcbdf {
public static void main(String[] args) {
Random free=new Random();
int f=free.nextInt(100)+1;//設定終極密碼的數字
//(這個無法重複,所以用do while的時候要移到外面)
int s;
do {
Scanner sc = new Scanner(System.in);//準備要猜的數字
s = sc.nextInt();
if (s == f) {
System.out.println("中獎");
break;//中獎將不會繼續猜下去(終止)
} else if (s > f) {
System.out.println("too big");
} else {
System.out.println("too small");
}
} while (s>0&&s<=100);//(猜的數字大於0)
}
}
import java.util.Random;
import java.util.Scanner;
public class milly2 {
public static void main(String[] args) {
Random ran=new Random();
int r=ran.nextInt(100)+1;
long product = 1;
int x;
do{
Scanner sc =new Scanner(System.in);
System.out.println("請輸入值");
x=sc.nextInt();
if (x==r){
System.out.println("猜對了");
break;
}
else if(x>r)
System.out.println("太大了!");
else
System.out.println("太小了");
}while(x>0 && x<100);
public class ex {
public static void main(String[] args) {
int target, guess;
java.util.Scanner sc=
new java.util.Scanner(System.in);
target = (int) (Math.random()*100+1);
do {
System.out.print("輸入猜測值=> ");
guess = sc.nextInt();
if ( guess == target ) {
break;
}
else {
if ( guess > target )
System.out.println("太大!");
else
System.out.println("太小!");
}
} while ( true );
System.out.println("猜中數字" + target);
}
}
import java.util.*;
public class ex2 {
public static void main(String[] args) {
int r,a;
Random ran = new Random();
r = ran.nextInt(100)+1;
do {
Scanner scan = new Scanner(System.in);
System.out.println("輸入數字");
a = scan.nextInt();
if(a<1||a>100)
break;
else if (a == r) {
System.out.println("Bingo");
break;
}
else if (a > r)
System.out.println("太大");
else
System.out.println("太小");
} while (a>=1&&a<=100);
}
}
import java.util.*;
public class ex7 {
public static void main(String[] args) {
Random ran = new Random();
int r=ran.nextInt(100)+1;
int x;
do{
Scanner sc =new Scanner(System.in);
System.out.println("請輸入值:");
x=sc.nextInt();
if(x==r){
System.out.println("猜對了!");
break;
}
else if(x>r)
System.out.println("太大了!");
else
System.out.println("太小了!");
}while(x>0 && x<100);
}
}
import java.util.Random;
import java.util.Scanner;
public class jj
{
public static void main(String[] args)
{
Random rnd=new Random();
Scanner sc = new Scanner(System.in);
int x=rnd.nextInt(100)+1;
int c;
do {
System.out.print("請輸入猜測值=>");
c=sc.nextInt();
if(c==x)
System.out.println("恭喜中獎");
else
if(c>x)
System.out.println("數字太小");
else
System.out.println("數字太大");
}while(x!=c);
}
}
import java.util.Random;
import java.util.Scanner;
public class qqq {
public static void main(String[] args) {
Random ran = new Random();
Scanner sc = new Scanner(System.in);
int guess = ran.nextInt(100)+1;
int target;
do {
System.out.print("請輸入猜測值=> ");
target= sc.nextInt();
if (guess == target)
System.out.print("猜對");
else if (guess > target)
System.out.println("數字太大");
else
System.out.println("數字太小");
} while (guess!=target);
}
}
package hello;
import java.util.Scanner;
public class ex1 {
public static void main(String[] args) {
int target, guess;
java.util.Scanner sc =
new java.util.Scanner(System.in);
target = (int)(Math.random()*100 + 1);
do {
System.out.print("請輸入猜測值=> ");
guess = sc.nextInt();
if ( guess == target ) {
break;
}
else {
if ( guess > target )
System.out.println("數字太大");
else
System.out.println("數字太小");
}
} while ( true );
System.out.println("猜中數字 :" + target);
}
}
package hello;
import java.util.Scanner;
public class ex1 {
public static void main(String[] args) {
int target, guess;
java.util.Scanner sc =
new java.util.Scanner(System.in);
target = (int)(Math.random()*100 + 1);
do {
System.out.print("請輸入猜測值=> ");
guess = sc.nextInt();
if ( guess == target ) {
break;
}
else {
if ( guess > target )
System.out.println("數字太大");
else
System.out.println("數字太小");
}
} while ( true );
System.out.println("猜中數字 :" + target);
}
}
import java.util.Random;
import java.util.Scanner;
public class s3 {
public static void main(String[] args) {
Random ran = new Random();
Scanner sc = new Scanner(System.in);
int Y = ran.nextInt(100)+1;
int S;
do {
System.out.print("請輸入數字=> ");
S= sc.nextInt();
if (Y == S)
System.out.print("猜對");
else if (Y > S)
System.out.println("數字太大");
else
System.out.println("數字太小");
} while (Y!=S);
}
}
import java.util.*;
public class ex1 {
public static void main(String[] args) {
Random ran = new Random();
int x =ran.nextInt(100)+1;
int z;
do {
Scanner aaa = new Scanner(System.in);
System.out.println("請輸入值:");
z = aaa.nextInt();
if (z > x)
System.out.println("太大");
else if (z < x)
System.out.println("太小");
else
System.out.println("得獎囉");
} while (z>0 && z<=100);
}
}
import java.util.Random;
import java.util.Scanner;
public class s3 {
public static void main(String[] args) {
Random ran = new Random();
Scanner sc = new Scanner(System.in);
int Y = ran.nextInt(100)+1;
int S;
do {
System.out.print("請輸入數字=> ");
S= sc.nextInt();
if (Y == S)
System.out.print("猜對");
else if (Y > S)
System.out.println("數字太大");
else
System.out.println("數字太小");
} while (Y!=S);
}
}
張貼留言