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

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

學(xué)java搞不懂y=m*x+b

學(xué)java搞不懂y=m*x+b

不負(fù)相思意 2022-01-12 14:30:49
創(chuàng)建代數(shù)導(dǎo)師,嘗試創(chuàng)建隨機(jī)整數(shù)來解決 y=m*x+b。搜索并發(fā)現(xiàn)很多用戶都使用過這個方程,但沒有生成一個隨機(jī)問題來要求答案并檢查是否正確。這是我到目前為止所寫的;import java.util.Scanner;class AlgebraTutor {  private static Scanner in = new Scanner(System.in);  public static void main(String[] args) {      for (int x = 0; x < 1; x++){          System.out.println("X = " + ((int)(Math.random() * 200) -99));      }          for (int m = 0; m < 1; m++){          System.out.println("M = " + ((int)(Math.random() * 200) -99));      }      for (int b = 0; b < 1; b++){          System.out.println("B = " + ((int)(Math.random() * 200) -99));      }  }}    我相信我在生成 -100 和 100 之間的數(shù)字的正確道路上。我只是不知道該怎么做才能將它們組合起來,以便我可以輸入創(chuàng)建數(shù)字的答案。我最好的猜測是System.out.print("Y = " + m * x + b);但這并沒有像我想象的那樣奏效。我希望能夠輸入答案并讓它檢查真假。感謝您提供解決此問題的任何建議。
查看完整描述

2 回答

?
慕慕森

TA貢獻(xiàn)1856條經(jīng)驗 獲得超17個贊

您需要將值存儲在變量中,例如:


int x = ((int)(Math.random() * 200) -99));

此外,您的 for 循環(huán)是不必要的,因為它們只運行一次,因此您可以只運行程序而不是循環(huán)一次。


所以最后你的代碼應(yīng)該是這樣的:


import java.util.Scanner;

class AlgebraTutor {

  private static Scanner in = new Scanner(System.in);

  public static void main(String[] args) {

      int x = ((int)(Math.random() * 200) -99);

      int m = ((int)(Math.random() * 200) -99);

      int b = ((int)(Math.random() * 200) -99);

      System.out.println("X = " + x);

      System.out.println("M = " + m);

      System.out.println("B = " + b);

      System.out.println("Y = " + m*x+b);


  }

}   

要讓它檢查答案是對還是錯,您必須執(zhí)行以下操作:


import java.util.Scanner;

class AlgebraTutor {

  private static Scanner in = new Scanner(System.in);

  public static void main(String[] args) {

      int x = ((int)(Math.random() * 200) -99);

      int m = ((int)(Math.random() * 200) -99);

      int b = ((int)(Math.random() * 200) -99);

      int y = m*x+b;

      System.out.println("X = " + x);

      System.out.println("M = " + m);

      System.out.println("B = " + b);

      int INPUT = in.nextInt();

      if(INPUT == y){

         System.out.println("You Got It Right!");

         System.out.println("Y = " + y);

      } else {

         System.out.println("You Got It Wrong :(");

         System.out.println("The Answer was: Y = " + y);


      }

   }


查看完整回答
反對 回復(fù) 2022-01-12
?
烙印99

TA貢獻(xiàn)1829條經(jīng)驗 獲得超13個贊

您示例中的變量 x、m 和 b 在每個 for 循環(huán)的范圍內(nèi),但}在循環(huán)之后死亡。


int x = (int)(Math.random() * 200) -99); // these variables will live long enough.

int m = (int)(Math.random() * 200) -99);

int b = (int)(Math.random() * 200) -99);


System.out.println("X = " + x);

System.out.println("M = " + m);

System.out.println("B = " + b);



System.out.print("Y = " + m * x + b);

這應(yīng)該有效,但請注意,當(dāng)您嘗試將這些數(shù)字除以“x/b”時要小心 - 您需要強(qiáng)制轉(zhuǎn)換為浮點數(shù)(谷歌除以整數(shù))


查看完整回答
反對 回復(fù) 2022-01-12
  • 2 回答
  • 0 關(guān)注
  • 192 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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