Results 1 to 2 of 2
- 11-15-2007, 12:02 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 2
- Rep Power
- 0
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 :confused:
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...:(
- 11-15-2007, 02:32 PM #2
Similar Threads
-
How to change JDK?
By mew in forum EclipseReplies: 5Last Post: 05-21-2010, 05:21 AM -
How ro change the locale of JVM
By ravi.ks007@hotmail.com in forum Advanced JavaReplies: 2Last Post: 12-26-2007, 06:17 AM -
Change my for loop
By javaplus in forum New To JavaReplies: 4Last Post: 12-12-2007, 11:00 AM -
change colors
By calblue in forum New To JavaReplies: 1Last Post: 12-02-2007, 11:52 PM -
How to change the resolution ?
By samson in forum Java 2DReplies: 1Last Post: 07-17-2007, 11:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks