View Single Post
  #1 (permalink)  
Old 11-15-2007, 02:02 PM
johnny7white johnny7white is offline
Member
 
Join Date: Nov 2007
Posts: 2
johnny7white is on a distinguished road
Send a message via MSN to johnny7white
Is it possible to change the '\n' into ' ' ...
in a program so that I don't have to press enter in order to get a result but spacebar instead? ...and secondly why is this not working

import java.io.*;
public class askisi1aApp
{
public static void main (String args[]) throws IOException
{
char operator;
int operand;
int result;
char answer;
do
{
result = my.readInt ();
//System.out.print (result + " ");
operator = (char) System.in.read ();
while( operator != '=')
{
operand = my.readInt ();
switch (operator)
{
case '+': result += operand;
break;
case '-': result -= operand;
break;
case '*': result *= operand;
break;
case '/': result /= operand;
break;
default: System.out.println ("invalid operator");
System.exit (1);
}
//System.out.print (operator + " ");
//System.out.print (operand + " ");
operator = (char) System.in.read ();
}
System.in.skip (2);
System.out.println (/*"= " + */result);
System.out.print ("try again (Y/N) ?");
answer = (char) System.in.read ();
}
while (answer=='Y' || answer=='y');
}
}

the idea is to make a program that calculates from left to right like that : 5 + 10 * 2 = 30
please help...
Reply With Quote
Sponsored Links