第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Java中使用for循環(huán)時打印非對稱值

如何在Java中使用for循環(huán)時打印非對稱值

胡子哥哥 2021-07-08 09:07:56
我想使用 for 循環(huán)實現(xiàn)一個矩陣。為了創(chuàng)建矩陣,我使用了 Jama Matrix Package。這是我的代碼import Jama.Matrix;public class Matrixnonsym {   public static void main(String args[]) {       Matrix Mytest=new Matrix(5,5);       for(int i=0; i<4; i++) {           Mytest.set(i,i,1);           Mytest.set(i+1,i,1);       }       Mytest.print(9,6);   }}這是我的輸出:1.000000   0.000000   0.000000   0.000000   0.0000001.000000   1.000000   0.000000   0.000000   0.0000000.000000   1.000000   1.000000   0.000000   0.0000000.000000   0.000000   1.000000   1.000000   0.0000000.000000   0.000000   0.000000   1.000000   0.000000沒有編譯錯誤或運行時錯誤。困難在于我怎么能讓 (0,0) 單元格值為 2?由于此矩陣使用 for 循環(huán)構(gòu)建,因此所有值都是對稱構(gòu)建的。那我怎么能只制作一個具有不同值的單元格呢?愿望輸出:2.000000   0.000000   0.000000   0.000000   0.0000001.000000   1.000000   0.000000   0.000000   0.0000000.000000   1.000000   1.000000   0.000000   0.0000000.000000   0.000000   1.000000   1.000000   0.0000000.000000   0.000000   0.000000   1.000000   0.000000
查看完整描述

3 回答

?
嚕嚕噠

TA貢獻1784條經(jīng)驗 獲得超7個贊

您可以在 for 循環(huán)中使用 if 條件為特定單元格設(shè)置不同的值。


import Jama.Matrix;


public class Matrixnonsym {

public static void main(String args[]){

     Matrix Mytest=new Matrix(5,5);

     for(int i=0;i<4;i++){

         if(i == 0){

               Mytest.set(i,i,2);

         }

         Mytest.set(i,i,1);

         Mytest.set(i+1,i,1);

      }

    Mytest.print(9,6);

}

}


查看完整回答
反對 回復(fù) 2021-07-14
?
蝴蝶刀刀

TA貢獻1801條經(jīng)驗 獲得超8個贊

我以前從未使用過 Jama,但從 Javadoc 來看,我認為您可以這樣做:


import Jama.Matrix;


public class Matrixnonsym {

public static void main(String args[]){

    Matrix Mytest=new Matrix(5,5);

    for(int i=0;i<4;i++){

        Mytest.set(i,i,1);

        Mytest.set(i+1,i,1);

    }

    Mytest.set(0, 0, 2.0) 

    Mytest.print(9,6);

}

}


查看完整回答
反對 回復(fù) 2021-07-14
?
當年話下

TA貢獻1890條經(jīng)驗 獲得超9個贊

import Jama.Matrix;


public class Matrixnonsym {

  public static void main(String args[]){

     Matrix Mytest=new Matrix(5,5);


     // first column

     Mytest.set(0,0,2);

     Mytest.set(1,0,1);


     // others columns

     for(int i=1; i<4; i++){

         Mytest.set(i,i,1);

         Mytest.set(i+1,i,1);

     }


     Mytest.print(9,6);

  }

}

或者


import Jama.Matrix;


public class Matrixnonsym {

  public static void main(String args[]){

     Matrix Mytest=new Matrix(5,5);


     for(int i=0; i<4; i++){

         Mytest.set(i, i, i == 0 ? 2 : 1);

         Mytest.set(i+1, i, 1);

     }


     Mytest.print(9,6);

  }

}


查看完整回答
反對 回復(fù) 2021-07-14
  • 3 回答
  • 0 關(guān)注
  • 171 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號