代碼如下:
創(chuàng)新互聯(lián)是一家專注于網(wǎng)站設(shè)計(jì)制作、成都做網(wǎng)站與策劃設(shè)計(jì),西安網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:西安等地區(qū)。西安做網(wǎng)站價格咨詢:028-86922220
public?class?App?{
public?static?void?main(String[]?args)?{
//?計(jì)算?6?*?4?結(jié)果放入?result
int?result?=?6?*?4;
//?輸出
System.out.println("result?=?"?+?result);
}
}
package ch02;
public class TEST{
public static void main(String[] args) {
for (int i = 1; i =9; i++) {
for (int j = 1; j = i; j++) {
System.out.print(j+"*"+i+"="+(i*j)+" ");
}System.out.println();
}
}
}
測試結(jié)果 :
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
實(shí)現(xiàn)思路:如果我們把九九乘法表中如“1*1=1”等式全部看作一個個整體的話,九九乘法表可看作一個直角三角形,實(shí)現(xiàn)直角三角形可用兩個for循環(huán)嵌套來實(shí)現(xiàn),那么我們最后輸出應(yīng)為System.out.print(變量1+"*"+變量2+"="+(變量1*變量2)+" ");
代碼如下:
public class ChengDemo {
public static void main(String args[]){
for(int k = 1;k=9;k++){ ? ? ? ? //外循環(huán)用于控制行數(shù) ? ? ?
for(int j = 1;j=k;j++){ ? ? ? ? ?
System.out.print(j+"*"+k+"="+(j*k)+"\t"); ? ? //"\t"為制表符
} ?
System.out.println(); ?//換行
}
}
}
用Java程序?qū)崿F(xiàn)九九乘法口訣表,可以用for()循環(huán)的方法來實(shí)現(xiàn),代碼如下:
/**
*?
*?用java實(shí)現(xiàn)九九乘法表
*?for()循環(huán)
*
*/
public?class?Testjiujiuchengfabiao?{
public?static?void?main(String[]?args)?{
//外層循環(huán)控制行數(shù),9行。
//內(nèi)存循環(huán)控制列數(shù)、數(shù)量。
for(int?i=1;i=9;i++)?
{
for(int?j=1;j=i;j++)
{
System.out.print(i+"*"+j?+"="?+(i*j)?+"\t");
}
//換行顯示
System.out.println();
}
}
}
//早前寫的,簡易的!
import?java.util.*;
public?class?TestSum?{
static?Scanner?sc?=?new?Scanner(System.in);
public?static?void?main(String[]?args)?{
while(true){
init();
}
}
private?static?void?init()?{
System.out.println("請輸入算數(shù)表達(dá)式如:1+1回車即可:");
String?str?=?sc.nextLine();
if?(!str.matches("[^a-zA-Z()^#$@!~]+"))?{
System.out.println("輸入錯誤重輸:請輸入算數(shù)表達(dá)式如:1+1回車即可:");
str?=?sc.nextLine();
}
int?q?=?0,?h?=?0,?sum?=?0;
char?chs?=?'?';
for?(int?i?=?0;?i??str.length();?i++)?{
chs?=?str.charAt(i);
if?(chs?==?'+'?||?chs?==?'-'?||?chs?==?'*'?||?chs?==?'/')?{
q?=?Integer.valueOf(str.substring(0,?i));
h?=?Integer.valueOf(str.substring(i?+?1,?str.length()));
switch?(chs)?{
case?'+':
sum?=?q?+?h;
break;
case?'-':
sum?=?q?-?h;
break;
case?'*':
sum?=?q?*?h;
break;
default:
sum?=?q?/?h;
break;
}
break;
}
}
System.out.println("結(jié)果="+sum+"\n繼續(xù)下一輪:");
}
}
本文標(biāo)題:java乘法運(yùn)算代碼 java中乘法函數(shù)
當(dāng)前路徑:http://jinyejixie.com/article32/dosddpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、ChatGPT、外貿(mào)建站、定制開發(fā)、響應(yīng)式網(wǎng)站、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)