Hi,

This is my first post in the forum. I am not new to java but I never tried to write a program seriously by myself. I thought to learn and write programs in java. This is my program converting Infix to Postfix expression using stacks. I wrote the program but can you say, to what extent it is correct and the standard of my programming and suggest me who I should learn to write in a correct way that is dynamic programming which works perfectly. For the below program I gave the input as,

Input:
------
a=b+c*d-e/f

//I did not use parenthesis for the expression in the program. Once this is correct I would extend my program.

Output:
-------
a=b+c*d-e/f
the entered string is:a=b+c*d-e/f
a
b+c*d-e/f
PUSH b
PUSH c
ADD
PUSH d
MUL
PUSH e
SUB
PUSH f
DIV

---------------------------------------------------------------------------

import java.io.*;
import java.util.*;
public class InToPostfix
{
public static void main(String[] args)throws Exception
{
String ch;
Stack s2 = new Stack();
System.out.println("enter the expression");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
while ((ch = br.readLine()) != null)
{
System.out.println("the entered string is:"+ch);
String str = new String(ch);
int l = str.length();
String s3 = (str.substring(0,1));
System.out.println(s3);
String s4 = (str.substring(2,l));
System.out.println(s4);
Stack s1 = new Stack();
for(int i=0;i<s4.length();i++)
{
char c2=s4.charAt(i);
if((c2>='a'&&c2>='z')||(c2>='A'&&c2<='z')||(c2>='0 '&&c2<='9'))
{
System.out.println("PUSH " +s1.push(c2));
}
else
{
switch(c2)
{
case'+':
s2.push(c2);
break;
case'-':
s2.push(c2);
break;
case'*':
s2.push(c2);
break;
case'/':
s2.push(c2);
break;
}
if(s2.size()>1)
{
int a = s2.size();
for(a=0;a<1;a++)
{
char g = (char)s2.get(a);
if(g=='+')
System.out.println("ADD ");
else if(g=='-')
System.out.println("SUB ");
else if(g=='*')
System.out.println("MUL ");
else if(g=='/')
System.out.println("DIV ");
s2.remove(a);
}
}
}
}
s2.peek();
char h = (char)s2.peek();
if(h=='+')
{
System.out.println("ADD");
}
else if(h=='-')
{
System.out.println("SUB");
}
else if(h=='*')
{
System.out.println("MUL");
}
else if(h=='/')
{
System.out.println("DIV");
}
}
}catch(Exception e){}
}
}