作者在 2008-11-21 15:05:04 发布以下内容
1.数组法
public class chengfabiao {
public static void main(String[] args) {
int[] a = new int[10]; //数组里的数字最好大于9
int[] b = new int[10];
int m = 0;
System.out.println("-----------------");
for (int i = 1; i < 10; i++) { //FOR后面的()里一定要加INT
a[i] = i;
int[] b = new int[10];
int m = 0;
System.out.println("-----------------");
for (int i = 1; i < 10; i++) { //FOR后面的()里一定要加INT
a[i] = i;
for (int j = 1; j <=i; j++) {
b[j]= j;
m = b[j] * a[i];
System.out.print(i+"*"+j+"="+m+"\t"); 是print不是println
if(i==j)
System.out.println( );
b[j]= j;
m = b[j] * a[i];
System.out.print(i+"*"+j+"="+m+"\t"); 是print不是println
if(i==j)
System.out.println( );
}
}
}
}
2.不用数组
public class jiujiu
{
public static void main(String [] args)
{
for(int i=1;i<10;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(i+"*"+j+"="+i*j+"\t");
if(i==j)
System.out.println();
}
}
}
}
{
public static void main(String [] args)
{
for(int i=1;i<10;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(i+"*"+j+"="+i*j+"\t");
if(i==j)
System.out.println();
}
}
}
}
3.continue法。//注意大括号的位置
public class Jiu1
{
//private static int j;
{
//private static int j;
public static void main(String [] args)
{
outer:
for(int i=1;i<10;i++)
{
inner:
for (int j=1;j<10;j++)
{
System.out.print(i+"*"+j+"="+i*j+"\t");
if(i==j)
{
System.out.println( );
continue outer;
}
}
}
}
}
{
outer:
for(int i=1;i<10;i++)
{
inner:
for (int j=1;j<10;j++)
{
System.out.print(i+"*"+j+"="+i*j+"\t");
if(i==j)
{
System.out.println( );
continue outer;
}
}
}
}
}
4.采用图形化的方法输出
public class Jiu2
{
public static void main(String [] args)
{
int i,j;
System.out.print(" * |");
for(i=1;i<=9;i++)
System.out.print(" "+i);
System.out.print("\n--------|");
for(i=1;i<10;i++)
System.out.print("-----");
System.out.println();
for(i=1;i<10;i++)
{
System.out.print(" "+i+" |");
for(j=1;j<=i;j++)
System.out.print(" "+i*j);
System.out.println();
}
}
{
public static void main(String [] args)
{
int i,j;
System.out.print(" * |");
for(i=1;i<=9;i++)
System.out.print(" "+i);
System.out.print("\n--------|");
for(i=1;i<10;i++)
System.out.print("-----");
System.out.println();
for(i=1;i<10;i++)
{
System.out.print(" "+i+" |");
for(j=1;j<=i;j++)
System.out.print(" "+i*j);
System.out.println();
}
}
}