㈠ 在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);
}
}