Discussion:
Help
(too old to reply)
Isaac Chan
2014-03-24 10:32:44 UTC
Permalink
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();}}
Eric Sosman
2014-03-24 12:36:35 UTC
Permalink
Post by Isaac Chan
Anyone knowing what is happening below?
It keeps bumping out the <identifier> expected error.
For future reference: It would have been helpful if you'd
pointed out which line provoked the error message. It would
also be a good idea to quote the *exact* and *complete* text
of error messages that puzzle you; the fact that you're puzzled
proves you don't know which bits are safe to omit.

Oh, yeah: Adopt a more reasonable formatting style. If
this sample had been a few lines longer I'd have just said
"Too much bother" and skipped it. But I'm in a good mood
today, so ...

There are a *lot* of things wrong with your code, but the
immediate issue the compiler objects to is
Post by Isaac Chan
private String Simplify(String cal ,char st ,char nd ,char new)
Take a close look at the name of the rightmost parameter.
--
Eric Sosman
***@comcast-dot-net.invalid
Joerg Meier
2014-03-24 13:00:23 UTC
Permalink
Post by Isaac Chan
Anyone knowing what is happening below?
public void Simplify_Test()
[...]
{SimplifyTest();}}
One with, the other without; so that's probably not going to work. It would
also be helpful if you too a look at the Java Code Conventions (easily
googleable). Other than the borderline unreadable formatting, you also make
various mistakes with how you name things that make it hard for anyone
familiar with Java to read your code.

For starters: dont use Names_Like_This but instead NamesLikeThis (this is
called CamelCase). Further, classes should be camel case start with an
uppercase letter (as yours does), but methods, fields and local variables
should all start with lower case names, so it should be simplifyTest and
simplifyGeneral.

Liebe Gruesse,
Joerg
--
Ich lese meine Emails nicht, replies to Email bleiben also leider
ungelesen.
Roedy Green
2014-03-25 15:16:41 UTC
Permalink
Post by Joerg Meier
Java Code Conventions
see http://mindprod.com/jgloss/codingconventions.html

Unfortunately my server is down. All the computers and UPSs were wiped
out by the mother of all power surges.
--
Roedy Green Canadian Mind Products http://mindprod.com
"A great lathe operator commands several times the wage of an average lathe
operator, but a great writer of software code is worth 10,000 times the
price of an average software writer."
~ Bill Gates
Roedy Green
2014-03-27 00:50:36 UTC
Permalink
On Tue, 25 Mar 2014 08:16:41 -0700, Roedy Green
Post by Roedy Green
see http://mindprod.com/jgloss/codingconventions.html
Unfortunately my server is down. All the computers and UPSs were wiped
out by the mother of all power surges.
back in business. Once you clean that up people can read your code.
--
Roedy Green Canadian Mind Products http://mindprod.com
"A great lathe operator commands several times the wage of an average lathe
operator, but a great writer of software code is worth 10,000 times the
price of an average software writer."
~ Bill Gates
Isaac Chan
2014-03-25 13:34:03 UTC
Permalink
Thanks a lot.I fix the major problems now.
Isaac Chan
2014-03-25 13:54:31 UTC
Permalink
I have fixed most of the problems.This is supposed to change ++ into + and -- into + and +- into -.Though it compile successfully ,it refuse to function.
I am new to this.Can u guys help me?


import java.util.Scanner;
class IngeniusXD
{Scanner scn = new Scanner(System.in);
private static String Simplify(String cal ,char st ,char nd ,char rep)
{for (int i = 0;i < cal.length() - 100; i++)
{if ((cal.charAt(i) == st) || (cal.charAt(i + 1) == nd))
{cal = cal.substring(0 ,i - 1) + rep + cal.substring(i + 2);}
else if ((cal.charAt(i) == nd) || (cal.charAt(i + 1) == st))
{cal = cal.substring(0 ,i - 1) + rep + cal.substring(i + 2);}}
return cal;}
public static String Simplify_General(String cal)
{cal = Simplify(cal ,'+' ,'-' ,'-');
cal = Simplify(cal ,'-' ,'-' ,'+');
cal = Simplify(cal ,'+' ,'+' ,'+');
return cal;}
public static void Simplify_Test()
{System.out.println("Simplify_Test:Input mathematical sentence");
Scanner scn = new Scanner(System.in);
String cal;
cal = scn.nextLine();
cal = Simplify_General(cal);
System.out.println("Simplify_Test:Output=" + cal);}
public static void main(String[] args)
{Simplify_Test();}}
Roedy Green
2014-03-25 15:17:52 UTC
Permalink
On Tue, 25 Mar 2014 06:54:31 -0700 (PDT), Isaac Chan
Post by Isaac Chan
public static String Simplify_General(String cal)
You drive people trying to help you crazy if you don't follow the
conventions. Methods start with lower case, classes with upper.
--
Roedy Green Canadian Mind Products http://mindprod.com
"A great lathe operator commands several times the wage of an average lathe
operator, but a great writer of software code is worth 10,000 times the
price of an average software writer."
~ Bill Gates
Knute Johnson
2014-03-25 15:55:41 UTC
Permalink
Post by Isaac Chan
I have fixed most of the problems.This is supposed to change ++ into + and -- into + and +- into -.Though it compile successfully ,it refuse to function.
I am new to this.Can u guys help me?
import java.util.Scanner;
class IngeniusXD
{Scanner scn = new Scanner(System.in);
private static String Simplify(String cal ,char st ,char nd ,char rep)
{for (int i = 0;i < cal.length() - 100; i++)
{if ((cal.charAt(i) == st) || (cal.charAt(i + 1) == nd))
{cal = cal.substring(0 ,i - 1) + rep + cal.substring(i + 2);}
else if ((cal.charAt(i) == nd) || (cal.charAt(i + 1) == st))
{cal = cal.substring(0 ,i - 1) + rep + cal.substring(i + 2);}}
return cal;}
public static String Simplify_General(String cal)
{cal = Simplify(cal ,'+' ,'-' ,'-');
cal = Simplify(cal ,'-' ,'-' ,'+');
cal = Simplify(cal ,'+' ,'+' ,'+');
return cal;}
public static void Simplify_Test()
{System.out.println("Simplify_Test:Input mathematical sentence");
Scanner scn = new Scanner(System.in);
String cal;
cal = scn.nextLine();
cal = Simplify_General(cal);
System.out.println("Simplify_Test:Output=" + cal);}
public static void main(String[] args)
{Simplify_Test();}}
It compiles, what is it supposed to do? What input are we to give it?
--
Knute Johnson
Lew
2014-03-25 22:12:01 UTC
Permalink
Post by Isaac Chan
I have fixed most of the problems.This is supposed to change ++ into + and -- into + and +- into -.Though it compile successfully ,it refuse to function.
I am new to this.Can u guys help me?
What is a "u guys"? People attached to a letter of the alphabet? I don't know if they can help you.
Post by Isaac Chan
import java.util.Scanner;
class IngeniusXD
Why not a 'public' class?
Post by Isaac Chan
{Scanner scn = new Scanner(System.in);
You have been coached to follow the coding conventions. You opted to ignore the advice.

No soup for you!
Post by Isaac Chan
private static String Simplify(String cal ,char st ,char nd ,char rep)
{for (int i = 0;i < cal.length() - 100; i++)
{if ((cal.charAt(i) == st) || (cal.charAt(i + 1) == nd))
{cal = cal.substring(0 ,i - 1) + rep + cal.substring(i + 2);}
else if ((cal.charAt(i) == nd) || (cal.charAt(i + 1) == st))
{cal = cal.substring(0 ,i - 1) + rep + cal.substring(i + 2);}}
return cal;}
public static String Simplify_General(String cal)
{cal = Simplify(cal ,'+' ,'-' ,'-');
cal = Simplify(cal ,'-' ,'-' ,'+');
cal = Simplify(cal ,'+' ,'+' ,'+');
return cal;}
public static void Simplify_Test()
{System.out.println("Simplify_Test:Input mathematical sentence");
Scanner scn = new Scanner(System.in);
String cal;
cal = scn.nextLine();
cal = Simplify_General(cal);
System.out.println("Simplify_Test:Output=" + cal);}
public static void main(String[] args)
{Simplify_Test();}}
Your problem is that your code is unreadable garbage.
--
Lew
Loading...