Can someone help me with a beginner's problem with java? (bluej)

Hi, I am a beginner to java programming, and I am using bluej to code my programs for my class.

I am trying to construct a calculator that works by having the user enter a equation in the form of a string with the scanner class, and then parse the Equation with stringtokenizer to answer their equation. However I have run into a slight problem on the last bit of coding. Does anyone know how to set an int variable equal to empty? I'm trying to set it sort of like String x = ""; so that the int is empty and therefore can be added to from the inside of a while loop. This is my code so far, my problem is in the parseEqn method.

/**

* Write a description of class M3L2T1 here.

*

* @author (your name)

* @version (a version number or a date)

*/

import java.util.Scanner;

import java.util.StringTokenizer;

class M3L2T1 {

public static void main (String[] args) {

Scanner sc = new Scanner (System.in);

StringTokenizer x;

String q = "";

System.out.println ("This program was created by -.");

System.out.println ();

System.out.println ("Simple Calculator program");

System.out.println ("This program will only accept a math expression with");

System.out.println ("2 operands and 1 operator. Acceptable operators");

System.out.println ("are +, -, *, /, and %. For example, 2*3 or 6%4.");

System.out.print ("Please enter an expression ending with the character (;) or put q to quit, then press enter: ");

String math = sc.nextLine();

System.out.println ();

while (!math.equals("q")) {

System.out.printf("%s = %d%n", math, parseEqn(math));

System.out.println ("Please enter an expression ending with the character (;) or put q to quit, then press enter: ");

math = sc.nextLine();

}

}

public static int parseEqn (String input) {

int equation = // on this line is my problem

StringTokenizer x = new StringTokenizer(input, "+-*/;");

while (x.hasMoreTokens()) {

String a = x.nextToken();

int aInt = Integer.parseInt(a);

String b = x.nextToken();

int bInt = Integer.parseInt(b);

if (a == ("+")) {

int plus = ((aInt)+(bInt));

return equation = plus;

} else if (a==("-")) {

int minus = ((aInt) - (bInt));

return equation = minus;

} else if (a == ("*")) {

int multiply = ((aInt) * (bInt));

return equation = multiply;

} else if (a == ("/")) {

int divide = ((aInt) / (bInt));

return equation = divide;

}

}

return equation;

}

}

Re: Can someone help me with a beginner's problem with java? (bluej)

First off welcome to the boards! Also its hard to read your code since you didn't use the code tags. String and ints are not the same thing. You can set an int to equal 0 like this.

Code:

`for (int i = 0; i < querySplit.length; i++) {`

String queryText = querySplit[i];

}