第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

請(qǐng)大神給我解釋一下下面這句JAVA語(yǔ)句的意思

請(qǐng)大神給我解釋一下下面這句JAVA語(yǔ)句的意思

霸氣又可愛的丹哥 2017-03-07 20:23:43
?int multiplyIndex = str.indexOf("x");? ? ? int divideIndex = str.indexOf("÷");? ? ? int firstOperationIndex = -1;? ? ? if (multiplyIndex == -1) firstOperationIndex = divideIndex;? ? ? if (divideIndex == -1) firstOperationIndex = multiplyIndex;? ? ? if (firstOperationIndex == -1) firstOperationIndex = Math.min(multiplyIndex, divideIndex);? ? ? String operation = str.substring(firstOperationIndex, firstOperationIndex+1);? ? ? String leftE = str.substring(0, firstOperationIndex-1);? ? ? String rightE = str.substring(firstOperationIndex+2);其中,str是例如“1+2+3x4+7”之類的字符串
查看完整描述

1 回答

已采納
?
習(xí)慣受傷

TA貢獻(xiàn)885條經(jīng)驗(yàn) 獲得超1144個(gè)贊

//舉例:str?=?1+2+3x4+7
//從字符串中查找“x”符號(hào)位置
//例子解析:x的位置為:5,所以?multiplyIndex=5
int?multiplyIndex?=?str.indexOf("x");
//從字符串中查找“÷”符號(hào)位置
//例子解析:str中沒有÷符號(hào),所以?divideIndex=-1
int?divideIndex?=?str.indexOf("÷");
//待計(jì)算的第一個(gè)操作索引
int?firstOperationIndex?=?-1;
//如果沒有找到乘法符號(hào)索引,那么第一個(gè)操作索引就賦值為除法符號(hào)索引
//例子解析:multiplyIndex?!=?-1,所以這句不執(zhí)行
if?(multiplyIndex?==?-1)?
	firstOperationIndex?=?divideIndex;
//如果沒有找到除法符號(hào)索引,那么第一個(gè)操作索引就賦值為乘法符號(hào)索引
//例子解析:divideIndex?==?-1,所以?firstOperationIndex?=?5
if?(divideIndex?==?-1)?
	firstOperationIndex?=?multiplyIndex;
//如果既沒有找到乘法符號(hào)也沒有找到除法符號(hào)索引,那么判斷它們之間最小的索引值。
//例子解析:firstOperationIndex?!=?-1,所以這句不執(zhí)行
if?(firstOperationIndex?==?-1)?
	firstOperationIndex?=?Math.min(multiplyIndex,?divideIndex);
//查找計(jì)算符號(hào)
//例子解析:執(zhí)行這句之后,operation="x"
String?operation?=?str.substring(firstOperationIndex,?firstOperationIndex+1);
//取操作符號(hào)左側(cè)字符串
String?leftE?=?str.substring(0,?firstOperationIndex-1);
//取操作符號(hào)右側(cè)字符串
String?rightE?=?str.substring(firstOperationIndex+2);


查看完整回答
3 反對(duì) 回復(fù) 2017-03-07
  • 1 回答
  • 0 關(guān)注
  • 1343 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)