印刷矩阵a& b

时间:2017-10-01 23:00:31

标签: java matrix jgrasp

我写的程序乘以3乘3矩阵。它要求用户输入矩阵a和矩阵b,然后显示其产品。我已经这样做但是我唯一的问题是输出只打印我想要打印$('#calendar').fullCalendar({ header: { left: 'prev,next', center: 'title', right: 'month,agendaDay' }, validRange: function(nowDate) { return { start: nowDate, end: nowDate.clone().add(2, 'months') }; }, hiddenDays: [ 2, 4 ], allDaySlot: false, lang:'es', slotEventOverlap:false, slotDuration: '00:60:00', slotMinutes: 60, timezone: 'America/Mexico_City', minTime: schedule_start+ ":00:00", maxTime: schedule_end+ ":00:00", defaultDate: '2017-09-12', slotLabelFormat:"HH:mm", contentHeight: window_height, navLinks: true, editable: false, selectable: true, selectOverlap:false, eventDurationEditable:true, selectConstraint:{ start: schedule_start+':00', end: schedule_end+':00', dow: [0, 1, 2, 3, 4, 5, 6 ] }, select: function(start, end, allDay,view) { save_start = $.fullCalendar.formatDate(start , "YYYY-MM-DD HH:MM:SS"); save_end = $.fullCalendar.formatDate(end, "YYYY-MM-DD HH:MM:SS"); }, events: reservations, eventRender: function(event, element, view) { // Agregamos el botón para eliminar la reservación if (view.name== 'agendaDay' && event.className =='new-reservation') { element.find(".fc-content").prepend('<span class="closeon"><i class="fa fa-window-close" aria-hidden="true"></i></span>'); } // Eliminamos la reservación del calendario delete element.find(".closeon").on('click', function() { delete_reservation(event.id,event.title); }); }, dayClick: function(date, jsEvent, view) { $('#calendar').fullCalendar('changeView', 'agendaDay', date); }, eventClick:function (calEvent, jsEvent, view){ $('#calendar').fullCalendar('changeView', "agendaDay",calEvent.start); } }); 的产品。我尝试将matrix a * matrix b = product(a,b)置于System.out.println(a[i][j]+ " ");之上 但它弄乱了所有的输出和乘法。

System.out.print(mul[i][j]+"");

2 个答案:

答案 0 :(得分:0)

逐列输出:您应该使用三个不同的循环来输出三个矩阵:矩阵a *矩阵b =乘积(a,b)

for(int i=0;i<3;i++){
   for(int j=0;j<3;j++)
   {
       System.out.print(a[i][j]+" ");                   
   }
   System.out.println();
}   

for(int i=0;i<3;i++){
   for(int j=0;j<3;j++)
   {
       System.out.print(b[i][j]+" ");                   
   }
   System.out.println();
}  

for(int i=0;i<3;i++){
   for(int j=0;j<3;j++)
   {
       System.out.print(mul[i][j]+" ");                   
   }
   System.out.println();
}  

行方式输出:为每一行创建一个StringBuffer。将第一行矩阵a,b和mul添加到StringBuffer1并将其打印出来。同样地,对于其他两行。 这是StringBuffer语法的链接。 http://www.java-examples.com/java-stringbuffer-examples

答案 1 :(得分:0)

你可以试试这个:

 System.out.println("Multiplication of two matrices:" + "\n");

 System.out.println("Matriz A");

 System.out.println(Arrays.deepToString(a) + "\n");

 System.out.println("Matriz B");

 System.out.println(Arrays.deepToString(b)+ "\n");

 System.out.println("A x B");

 System.out.println(Arrays.deepToString(mul)+ "\n");

结果:

Multiplication of two matrices:

Matriz A
[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]

Matriz B
[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]

A x B
[[30.0, 36.0, 42.0], [66.0, 81.0, 96.0], [102.0, 126.0, 150.0]]