Isaac Chan
2014-03-24 10:32:44 UTC
Anyone knowing what is happening below?
It keeps bumping out the <identifier> expected error.
import java.util.Scanner;
class IngeniusXD
{Scanner scn = new Scanner(System.in);
private String Simplify(String cal ,char st ,char nd ,char new)
{for (int i = 0;i < cal.length() -1; i++)
{if ((cal.charAt(i) == st) || (cal.charAt(i + 1) == nd))
{cal = cal.substring(0 ,i - 1) + new + cal.substring(i + 2);}
else if ((cal.charAt(i) == nd) || (cal.charAt(i + 1) == st))
{cal = cal.substring(0 ,i - 1) + new + cal.substring(i + 2);}}
return cal;}
public String Simplify_General(String cal)
{cal = Simplify(cal ,'+' ,'-' ,'-');
cal = Simplify(cal ,'-' ,'-' ,'+');
cal = Simplify(cal ,'+' ,'+' .'+');
return cal;}
public void Simplify_Test()
{System.out.println("Simplify_Test:Input mathematical sentence.");
cal = scn.next();
cal = Simplify_General(cal);
System.out.println("Simplify_Test:Output=");}
public static void main(String[] args)
{SimplifyTest();}}
It keeps bumping out the <identifier> expected error.
import java.util.Scanner;
class IngeniusXD
{Scanner scn = new Scanner(System.in);
private String Simplify(String cal ,char st ,char nd ,char new)
{for (int i = 0;i < cal.length() -1; i++)
{if ((cal.charAt(i) == st) || (cal.charAt(i + 1) == nd))
{cal = cal.substring(0 ,i - 1) + new + cal.substring(i + 2);}
else if ((cal.charAt(i) == nd) || (cal.charAt(i + 1) == st))
{cal = cal.substring(0 ,i - 1) + new + cal.substring(i + 2);}}
return cal;}
public String Simplify_General(String cal)
{cal = Simplify(cal ,'+' ,'-' ,'-');
cal = Simplify(cal ,'-' ,'-' ,'+');
cal = Simplify(cal ,'+' ,'+' .'+');
return cal;}
public void Simplify_Test()
{System.out.println("Simplify_Test:Input mathematical sentence.");
cal = scn.next();
cal = Simplify_General(cal);
System.out.println("Simplify_Test:Output=");}
public static void main(String[] args)
{SimplifyTest();}}