日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

Java基础类库四则运算_00JAVA语法基础_四则运算 01

發(fā)布時(shí)間:2025/4/16 java 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java基础类库四则运算_00JAVA语法基础_四则运算 01 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

packageSizeyunsuan;/*** 30道100以內(nèi)四則運(yùn)算

*

**/

public classRandom {public static int getRandom( int n, intm)

{//產(chǎn)生n->m的隨機(jī)數(shù)

return (int) (Math.random() * (m - n) +n);

}public static chargetCharRandom()

{//隨機(jī)產(chǎn)生四種運(yùn)算符

char sign = 0;intSn;

Sn= getRandom(1,5);switch(Sn)

{case 1:sign = '+' ;break;case 2:sign = '-' ;break;case 3:sign = '×' ;break;case 4:sign = '÷' ;break;

}returnsign;

}public static voidmain(String[] args) {//TODO Auto-generated method stub

int i = 0;do{int x = (int) (Math.random() * (100 - 1 )+ 1); //產(chǎn)生1-100的隨機(jī)數(shù)

int y = (int) (Math.random() * (100 - 1 )+ 1); //產(chǎn)生1-100的隨機(jī)數(shù)

char sign =getCharRandom();/** 判斷乘法的范圍*/

switch(sign)

{case '+':

System.out.println("("+ (i+1) +")"+ x + " " + sign + " " + y + "=");

i++;break;case '-':if(x < y) //判斷減數(shù)與被減數(shù)的大小關(guān)系

{inttemp;

temp=x;

x=y;

y=temp;

}

System.out.println("("+ (i+1) +")"+ x + " " + sign + " " + y + "=");

i++;break;case '×':

{

x= (int) (Math.random() * (10 - 1 )+ 1);//新生成x,y<9的隨機(jī)數(shù)

y = (int) (Math.random() * (10 - 1 )+ 1);

System.out.println("("+ (i+1) +")"+ x + " " + sign + " " + y + "=");

i++;

};break;case '÷':do //循環(huán)生成除法

{

y= (int) (Math.random() * (10 - 1 )+ 1);

x= (int) (Math.random() * (9*y - 1 )+ 1);

}while(x % y != 0) ;

System.out.println("("+ (i+1) +")"+ x + " " + sign + " " + y + "=");

i++;break;

}/*if(sign == '×')

{

x = (int) (Math.random() * (10 - 1 )+ 1);//新生成x,y<9的隨機(jī)數(shù)

y = (int) (Math.random() * (10 - 1 )+ 1);

System.out.println( "("+ (i+1) +")"+ x + " " + sign + " " + y + "=" );

i++;

}*/

/** 加減法判斷*/

/*if(sign == '+' || sign == '-')

{

if(x < y) //判斷減數(shù)與被減數(shù)的大小關(guān)系

{

int temp;

temp = x;

x = y;

y = temp;

}

System.out.println( "("+ (i+1) +")"+ x + " " + sign + " " + y + "=" );

i++;

}*/

/** 除法判斷*/

/*if(sign == '÷')

{

do //循環(huán)生成除法

{

y = (int) (Math.random() * (10 - 1 )+ 1);

x = (int) (Math.random() * (9*y - 1 )+ 1);

}

while(x % y != 0) ;

System.out.println( "("+ (i+1) +")"+ x + " " + sign + " " + y + "=" );

i++;

}*/}while(i<30);

}

}

總結(jié)

以上是生活随笔為你收集整理的Java基础类库四则运算_00JAVA语法基础_四则运算 01的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。