利用Random()產生1~100的隨機亂數
猜它到猜對為止!
herrDeng網內搜尋
自訂搜尋
Ads
訂閱:
張貼留言 (Atom)
熱門文章
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
先說明一下這是後知後覺的解答,所謂後知就是股票價格已知存在陣列(清單),當然就要用迴圈練習,雙迴圈暴力解需時O(n**2),當然不用,採python單一迴圈解答「最佳股票的買賣時機#LeetCode 121 Best Time to Buy and Sell Stock」,解...
-
你會用C的算子sizeof?
-
XOR prefixsum CPP python解Leetcode 1829 Maximum XOR for Each Query 其實這裡考慮的是元素個數為2^maximumBit的交換群,運算子為XOR。 [Python code請進]
-
Python C++使用字串find迴圈速解Leetcode 2490 Circular Sentence C++ & Python都有字串的find,用法都類似 split=s.find(' ', split+1)能找到s從index=split+1開...
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);
}
}
張貼留言