本文目錄一覽:
怎麼用java編寫程序實現九九乘法表?
代碼如下:
public class qct {
public static void main(String[] args)
{
int i=0;
int j=0;
for(i=1;i=9;i++)
{ for(j=i;j=9;j++)
System.out.print(i+”*”+j+”=”+i*j+”\t”);
System.out.println();
}
}
}
擴展資料
import java.lang.*;
import java.util.Arrays;
public class ChengFB
{
public static void main(String[] args)
{
int[] Num=new int[10];
for(int i=1;i10;i++)
{
Num[i]=i;
}
for(int m=9;m0;m–)
{
for(int j=9;j=m;j–)
{
int Result;
Result=Num[m]*Num[j];
System.out.print(Num[j]+”*”+Num[m]+”=”+Result+” “);
}
System.out.println();
}
}
public int Multi(int x,int y)
{
int temp;
temp=x*y;
return temp;
}
}
java 九九乘法表
肯定的啊.第二個程序循環
for (int j=1;j==i;j++){
System.out.print(i+”*”+j+”=”+(i*j)+”\t”);
}
i=1時,j=1,好吧,出來了1*1=1
j=2時,i==j不成立了,所以j不++了.所以j永遠是2了.永遠不等於,所以不會打印了.
i=2,3,4,5,6,7,8,9時
j開始等於1,結果j永遠不會等於i,所以j永遠是1了,後面的也就不會執行,不會打印了
用java實現三種方法循環輸出九九乘法表:
for循環的結構:for(表達式 1;表達式 2;表達式 3) { 循環體 }
表達式 1:一般為賦值表達式;
表達式 2:一般為關係表達式或邏輯表達式;
表達式 3:一般為賦值表達式或自增、自減表達式,用以修改循環變量的值。
while循環的結構: while(表達式) 循環體
1、while 是C語言中的關鍵字;
2、圓括號中的表達式可以是C語言中任意合法的表達式,不能為空,用它來控 制循環體是否執行;
3、循環體是一條語句,若需要使用多條語句,應使用複合語句(用{ }括起來);
4、若條件開始直接為假,則直接跳出循環。
do…while語句為先執行後判斷表達式的值。
1、do 是C語言的關鍵字,必須和while一起使用;
2、循環由do開始,由while結束;
3、循環體是一條語句,若需要使用多條語句,應使用複合語句(用{ }括起來);
4、圓括號中的表達式可以是C語言中任意合法的表達式,不能為空,用它來控 制循環體是否執行;
擴展資料:
一般形式為:
for(單次表達式;條件表達式;末尾循環體)
{
中間循環體;
}
其中,表示式皆可以省略,但分號不可省略,因為「;」可以代表一個空語句,省略了之後語句減少,即為語句格式發生變化,則編譯器不能識別而無法進行編譯。
for循環小括號里第一個「;」號前為一個為不參與循環的單次表達式,其可作為某一變量的初始化賦值語句, 用來給循環控制變量賦初值; 也可用來計算其它與for循環無關但先於循環部分處理的一個表達式。
倆「;」號之間的條件表達式是一個關係表達式, 其為循環的正式開端,當條件表達式成立時執行中間循環體。
執行的中間循環體可以為一個語句,也可以為多個語句,當中間循環體只有一個語句時,其大括號{}可以省略,執行完中間循環體後接着執行末尾循環體 。
執行末尾循環體後將再次進行條件判斷,若條件還成立,則繼續重複上述循環,當條件不成立時則跳出當下for循環。
Pascal語言中的for循環:
for 循環變量:=初值 to/downto 終值 do
begin
循環體
end;
循環變量從起點到終點每次加1或減1(to 為加1,downto為減1)。
Pascal
while 條件 do 語句
意為當條件符合時,接着做下面的語句;不符合時,退出循環。
C
do 語句 while(條件);
while(條件) 語句;
C++
while(條件) 語句;
do 語句 while(條件);
Java
while(條件) {語句;}
do {語句;} while(條件);
二者的區別是do-while最少會被執行一次。
循環中可以使用continue結束當前循環,回到循環開始處開始下一次循環。也可以用break跳出整個循環。
javascript
JavaScript中while循環的目的是為了反覆執行語句或代碼塊。
只要指定條件為true,循環就可以一直執行代碼塊。
JavaScript中while循環的語法如下:
while (條件) {需執行的代碼 };
do {需執行的代碼 } while (條件);
注意:do…while 循環是 while 循環的變種。該循環程序在初次運行時會首先執行一遍其中的代碼,然後當指定的條件為 true 時,它會繼續這個循環。所以可以這麼說,do…while 循環為執行至少一遍其中的代碼,即使條件為 false,因為其中的代碼執行後才會進行條件驗證。
PHP
while 循環是 php 中最簡單的循環類型。它和 C 語言中的 while 表現得一樣。語法如下:
while(expr){
statement
}
參考資料來源:百度百科–for循環
參考資料來源:百度百科–while
九九乘法表怎麼用JAVA語言編寫
如果把九九乘法表中如「1*1=1」等式全部看作一個個整體的話,九九乘法表可看作一個直角三角形,實現直角三角形可用兩個for循環嵌套來實現,那麼我們最後輸出應為System.out.print(變量1+”*”+變量2+”=”+(變量1*變量2)+” “)。
輸入代碼如下: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();}}}
測試結果 :
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
擴展資料:
Java 技術具有卓越的通用性、高效性、平台移植性和安全性,廣泛應用於PC、數據中心、遊戲控制台、科學超級計算機、流動電話和互聯網,同時擁有全球最大的開發者專業社群。
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();}}
參考資料:JAVA語言百度百科
JAVA輸出99乘法表
public class MultiplicationTable {
public static void main(String[] args) {
for (int i = 1 ; i = 9 ; i++){
for (int j = 1 ; j = i ; j++){
System.out.print(i + “*” + j + “=” + i * j + ” “);
}
System.out.println();
}
}
}
執行效果一:
1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=9
4*1=4 4*2=8 4*3=12 4*4=16
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
倒置的九九乘法表
public class ResupinateMultiplicationTable {
public static void main(String[] args) {
for (int i = 9 ; i = 1 ; i–){
for (int j = i ; j = 1 ; j–) {
System.out.print(i + “*” + j + “=” + i * j + ” “);
}
System.out.println();
}
}
}
執行效果二:
9*9=81 9*8=72 9*7=63 9*6=54 9*5=45 9*4=36 9*3=27 9*2=18 9*1=9
8*8=64 8*7=56 8*6=48 8*5=40 8*4=32 8*3=24 8*2=16 8*1=8
7*7=49 7*6=42 7*5=35 7*4=28 7*3=21 7*2=14 7*1=7
6*6=36 6*5=30 6*4=24 6*3=18 6*2=12 6*1=6
5*5=25 5*4=20 5*3=15 5*2=10 5*1=5
4*4=16 4*3=12 4*2=8 4*1=4
3*3=9 3*2=6 3*1=3
2*2=4 2*1=2
1*1=1
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/270428.html