Hello all. I would like to calculate, assign and do a lot with my program (java). Here are my codes.
import java.util.*;
public class Test
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
String[] s = new String[9];
int a;
for(a=0;a<9;a++)
{
s[a]=scan.next();
}
}
}
Here are my needs:
if the input is 1 2 3 4 5 6 =A1+A2 =A5+A3 =A5-A1
First i wd like to the program to recognize that the formulae start after the "=" sign, then allocate the string after the = sign to a position in the array(A1=s[0],A2=s[1] and so forfth), finally do the calulations and print the result as a matrix.(I know how to do all the rest but i'm stuck on these exceptional cases above). Thanks for help :=)
P.S.: There are spaces between the input.(1_2_3...).

2
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by sciwizeh

depends on the complexity of what kind of equations you want to be able to supply to it.

just addition and subtraction won't be too difficult for you, but if you want it to have MDAS then it will be slightly more complex, and PEMDAS is even more compex... i in fact have a thread on PEMDAS, and solved another on MDAS on this site, if that is what you need search for it on the site.

if you still need help after reading those threads, post more a more specific misunderstanding or problem

Thanks sciwizeh but i only wana do additions and subtractions. Thanks for help.

in that case, you can go through the string, find '=' and then take then get "a1" and associate it with the proper number in the beginning, then look at the symbol if use a flag for '+' or '-' then "a2" and associate it in the same fashion as "a1" then according to the flag set earlier either add or subtract "a2" from "a1"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.