【问题标题】:Systems of equations calculator getting "NaN"方程组计算器得到“NaN”
【发布时间】:2015-07-08 04:58:20
【问题描述】:

这是我的代码。

 import java.util.Scanner;
 import java.util.ArrayList;
  public class SysQ {

public static void main(String[] args) {
    Scanner keyboard = new Scanner (System.in);


System.out.print("Enter A: ");
double a = keyboard.nextDouble();
System.out.print("Enter B: ");
double b = keyboard.nextDouble();
System.out.print("Enter C: ");
double c = keyboard.nextDouble();
System.out.print("Enter X: ");
double x = keyboard.nextDouble();
System.out.print("Enter Y: ");
double y = keyboard.nextDouble();
System.out.print("Enter Z: ");
double z = keyboard.nextDouble();


   double fixedequation2 = x * b;
   double fixedequation3 = x * c;
   double fixedequation5 = a * y;
   double fixedequation6 = a * z;



double final1 = fixedequation2 - fixedequation5;
double final2 = fixedequation3 - fixedequation6;
double yanswer = final2/final1;



double x1 = c - (b * yanswer);
double xanswer = x1/a;

System.out.println("X is " + xanswer);
System.out.println("Y is " + yanswer);

所以代码适用于 2 x 2 方程的大多数数字,但是当我为 a、b、c、x、y、z 输入值 5、5、5、5、5、5 时,我得到“NaN”我只想知道“NaN”是指无限多的解决方案还是没有解决方案..

【问题讨论】:

    标签: java math nan


    【解决方案1】:

    NaN 表示“不是数字”。你得到那个解决方案是因为你在做

    (25-25)/(25-25) = 0/0,其结果未定义,或“不是数字”

    【讨论】:

    • 哦,我明白了,但这属于无解决方案还是无限多个解决方案?
    • @WinterOne 我猜你会说“没有解决方案”。数学上更高级的人可能会纠正我,因为它在技术上可能不正确。
    • @WinterOne 这种类型的表单是未定义的 0/0
    猜你喜欢
    • 2013-04-28
    • 1970-01-01
    • 2015-03-12
    • 2014-02-19
    • 2021-06-30
    • 2014-10-19
    • 1970-01-01
    • 1970-01-01
    • 2023-02-04
    相关资源
    最近更新 更多