亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

在帶有掃描儀的控制臺中顯示多個變量

在帶有掃描儀的控制臺中顯示多個變量

海綿寶寶撒 2021-05-07 18:20:26
問題是當您使用掃描儀輸入輸入時,它會顯示在控制臺上。我希望它們按順序顯示。我希望他們像母艦一樣顯示。但是,使用nextInt方法時,彼此之間都顯示出底部。我想要這樣的控制臺輸出:但是使用nextInt()方法,新的int會在nextLine上顯示,如下所示:如何在掃描儀的同一行中顯示多個變量?import java.util.Scanner;public class ProbilityMatrixTest {static int M;static int N;static float[][] matrixX;static float[][] matrixY;static boolean isProbilityMatrix;public static void main(String[] args) {    initiate();    testMatrix(matrixX);    System.out.println();    multiplyMatrix();    testMatrix(matrixY);}public static void initiate() {    Scanner sc = new Scanner(System.in);    System.out.print("Enter the row and column size of matrix : ");    M = sc.nextInt();    N = sc.nextInt();    System.out.println();    matrixX = new float[M][N];    System.out.println("Enter values of " + M + "x" + N + " matrix :");    for (int j = 0; j < N; j++) {        for (int i = 0; i < M; i++) {            matrixX[i][j] = sc.nextFloat();        }    }}public static void testMatrix(float[][] givenMatrix) {    isProbilityMatrix = true;    if (M != N) {        isProbilityMatrix = false;    }    for (int j = 0; j < N; j++) {        float rowVariablesTotal = 0;        for (int i = 0; i < M; i++) {            rowVariablesTotal += givenMatrix[i][j];            if (givenMatrix[i][j] < 0) {                isProbilityMatrix = false;            }        }        if (rowVariablesTotal != 1.0f) {            isProbilityMatrix = false;        }    }    System.out.print("TEST RESULT : ");    if (isProbilityMatrix) {        System.out.println("Probility matrix");    } else {        System.out.println("not Probility matrix");    }}public static void multiplyMatrix() {        matrixY = new float[M][N];        for (int i = 0; i < M; i++) {            for (int j = 0; j < N; j++) {                float newMatrixVariable = 0;                for (int a = 0; a < M; a++) {                    newMatrixVariable += (matrixX[i][a] * matrixX[a][j]);                }                matrixY[i][j] = newMatrixVariable;            }        }}}
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號