㈠ 在java中使用二維數組輸出九九乘法表
樓上不要誤導,乘法運算不就是從1到9么?
問題在這,int a[][]=new int[1][1]; 你定義的數組存放值最多隻能1,按理至少需要9,但乘法表從1開始,而JAVA的數組下標從0開始,所以數組內的二維 存放值應該是10
int a[][]=new int[10][10];
㈡ Java程序兩個一維數組相乘 然後輸出怎麼弄啊
public class Day25B {
public static void main(String[] args) {
int[] arr1=new int[5],arr2=new int[5],result=new int[5];
for (int i = 0; i < result.length; i++) {
arr1[i]=(int)Math.round(Math.random()*40+10);
arr2[i]=(int)Math.round(Math.random()*40+10);
result[i]=arr1[i]*arr2[i];
}
System.out.println("索引 arr1 arr2 result");
for (int i = 0; i < result.length; i++) {
System.out.println(i+" "+arr1[i]+" x "+arr2[i]+" = "+result[i]);
}
}
}
㈢ java實現數組相乘
你是川師計科4班的某某吧?
public class JuZheng {
private int a[][]=new int[2][3];
private final int b[][]={ {1,5,2,8},{5,9,10,-3},{2,7,-5,-18} };
public JuZheng(int s[][])
{ a=s; }
public int[][] Getb()
{
return b;
}
public int[][] GetArray()
{
int [][]array=new int[2][4];
for(int i=0;i<=1;i++)
{
for(int j=0;j<=3;j++)
{
array[i][j]=a[i][0]*b[0][j]+a[i][1]*b[1][j]+a[i][2]*b[2][j];
}
}
return array;
}
}
import java.util.Scanner;
public class Mian {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("*** Matrix A ***");
Scanner scanner=new Scanner(System.in);
int a[][]=new int[2][3];
for(int i=0;i<=1;i++)
{
for(int j=0;j<=2;j++)
{
a[i][j]=scanner.nextInt();
}
}
JuZheng juzheng=new JuZheng(a);
System.out.println("*** Matrix B ***");
for(int i=0;i<=2;i++)
{
for(int j=0;j<=3;j++)
{
System.out.print(juzheng.Getb()[i][j]+" ");
}
System.out.println();
}
System.out.println("*** Matrix C ***");
int s[][]=new int [2][4];
s=juzheng.GetArray();
for(int i=0;i<=1;i++)
{
for(int j=0;j<=3;j++)
{
System.out.print(s[i][j]+" ");
} System.out.println();
}
}
}
㈣ java編程實現任意兩個數組的乘法運算
mport java.util.Scanner;
public class liujian {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
A num;
num=new A();
Scanner in = new Scanner(System.in);
System.out.print("輸入第一個數:");
num.a = in.nextInt();
System.out.print("輸入第二個數:");
num.b = in.nextInt();
System.out.println("兩數相加的結果為:");
System.out.println(num.a+num.b);
System.out.println("兩數相減的結果為:");
System.out.println(num.a-num.b);
System.out.println("兩數相乘的結果為:");
System.out.println(num.a*num.b);
System.out.println("兩數相除的結果為:");
System.out.println(num.a/num.b);
System.out.println("兩數平方的結果為:");
System.out.println(num.a*num.b);
}
}
class A{
int a,b;
void jjcc(int s){
System.out.println(s);
}
}