利用Random()產生1~100的隨機亂數
猜它到猜對為止!
herrDeng網內搜尋
自訂搜尋
Ads
訂閱:
張貼留言 (Atom)
熱門文章
-
計算你的BMI
-
1. 利用遞迴input n算2^n 2. 用C算GCD(3333,456)
-
請用 C/C++/java寫一簡易程式
-
33, 45, 87, 99, 27 算平均
-
一、 試利用switch case由程式中直接輸入一個1~7 之間的整數day,代表星期一到星期日。若day 的值是1,則印出 "星期一",若day 的值是2,則印出 "星期二",若day 的值是7,則印出 "星期日",...
-
BMI (Body Mass Index)= 體重 (kg) / 身高 ^2(m 2 ) 在台灣,行政院衛生署乃根據其相關研究,於2002年4月公佈台灣成人肥胖標準: BMI<18.5 為過輕, 18.5≦BMI<24 為正常體重, 24≦BMI<27 為過重, BM...
-
需要練習的Java程式:
-
用 C/C++算上學期加權平均
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);
}
}
張貼留言