我想使用數學克拉默定理做一個確定性計算器,正如你所看到的,我將該定理轉化爲代碼convertedString = Convert.ToString (x * y1 * 1 + x1 * y2 * 1 + x2 * x * y - (1 * y1 * x2 + 1 * y2 * y + 1 * y * x1));
所有的好東西,直到我需要計算2個未知數的時候,我不知道如何在代碼中告訴「x + x = 2x
」或「3y-y = 2y
」,所以我認爲如果將Crammer方程轉換爲字符串,我可以找到所有匹配,如x + x
或y + 2y
或y * y
,並從該解決方案開始解決我的初始問題,就像我找到x * x
模式一樣,我會通過if語句或者x * x
模式爲x^2
的東西來告訴PC。 所以說,我想找出一些特定的序列,如X * y
或y + x
存在於一個字符串中,我嘗試了一些foreach
循環和for
循環,但我不能讓它工作,我不知道我應該如何接下來的問題,尋求幫助。我應該如何通過字符串搜索字符序列,如「x * y」?
這裏是我的代碼:
using System;
using InputMath;
namespace MathWizard
{
class Determinants
{
//Determinant of a first point and a second graphical point on the xoy axis.
public static void BasicDeterminant()
{
float x;
float y;
float x1 = Input.x1;
float y1 = Input.y1;
float x2 = Input.x2;
float y2 = Input.y2;
float result;
string convertedString;
string pointsValue;
string[] point;
Console.WriteLine("Please introduce the 2 graphical points (A and B) \n in the order x1 y1 x2 y2, separated by a space ");
pointsValue = Console.ReadLine();
point = pointsValue.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
x1 = Convert.ToInt32(point[0]);
y1 = Convert.ToInt32(point[1]);
x2 = Convert.ToInt32(point[2]);
y2 = Convert.ToInt32(point[3]);
//The Cramer's Rule for solving a 2 points determinant (P1(x1,y1) and P2(x2,y2)
convertedString = Convert.ToString (x * y1 * 1 + x1 * y2 * 1 + x2 * x * y - (1 * y1 * x2 + 1 * y2 * y + 1 * y * x1));
}
}
}
你聲明'x1,x2,y1,y2'爲'float',但是然後使用'Convert.ToInt16'從輸入中獲取它們。哪種類型是正確的? –
此代碼不包含有關查找字符串的任何內容。你想達到什麼目的? – PhilMasterG
您是否複製/粘貼其他人的代碼,然後嘗試修改它?這個不成立。 'x'和'y'總是'1',你也有一些硬編碼的'1',全部用於乘法。 –