hi there everyone! :D i'm new here and i'm wondering if you can help me with my java programming. actually it is my project and i'm having a difficult time with it. here is is my code. its about array computation, 1st you will input how many operators you will use and then after that the program will ask about what kind of operators you will use, and then the no. of operands will be shown. my problem is how can i compute the operands that i inserted. oh, by the way i use an array in it.

import java.io.*;


public class project_test1{
public static void main(String args[])throws Exception{


char optr [];
int counter, no_op, op;
double oprnd [], total=0;
BufferedReader x = new BufferedReader (new InputStreamReader (System.in));

do{
	
	System.out.print("Enter no. of Operators: ");
	no_op = Integer.parseInt(x.readLine());
	optr = new char [no_op];

	System.out.println();
	System.out.println();

}while (no_op>=6);

	for (counter = 0; counter<no_op; counter++)

{

	System.out.print("Operator [" + (counter+1) + "]: ");
	optr [counter] = (char)System.in.read();
	System.in.read(); System.in.read();

}

do{

	System.out.println();
	System.out.println();
	
	op = no_op+1;
	System.out.print("No. of Operands: " + (op));
	oprnd = new double [op];

	System.out.println();
	System.out.println();

}while (op>=7);

	for (counter = 0; counter<op; counter++)

{

	System.out.print("Operands [" + (counter+1) + "]: " );
	oprnd [counter] = Double.parseDouble(x.readLine());

}

	
for(counter = 0; counter<no_op; counter++)

{

	
	System.out.println();
	System.out.println("Operand [" + (counter+1) + "]: " + oprnd [counter]);
	System.out.print("Operator [" + (counter+1) + "]: " + optr [counter]);

}
	
	System.out.println();
	System.out.print("Operand [" +(counter+1) + "]: " + oprnd [counter]);

total = oprnd[0];
for (counter = 0; counter<no_op; counter++)
{
switch(optr[counter])
{

	case '+' : total += oprnd [counter];
	break;

	case '-' : total -= oprnd [counter];
	break;

	case '*' : total *= oprnd [counter];
	break;

	case '/' : total /= oprnd [counter];
	break;

	case '%' : total %= oprnd [counter];
	break;

default:

}
}
System.out.println();
System.out.print(total);


}
}

please help about this, if i don't explain my problem clearly, just run the code and you will find out. thank you so much for anyone who will help me this. :)

Hi neow and welcome to Daniweb,

I'm not sure what you meant by the statement:

my problem is how can i compute the operands that i inserted.

Do you mean how do you get the operands from the user input? Or are you asking how to compute the entire equation once the user has inputted the operands and operators?

the second one, how to compute entire equation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.