The Artima Developer Community
Sponsored Link

Java Answers Forum
need help please

2 replies on 1 page. Most recent reply: Oct 11, 2002 7:15 PM by hyderman

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
salem

Posts: 2
Nickname: salemjr
Registered: Oct, 2002

need help please Posted: Oct 10, 2002 5:51 PM
Reply to this message Reply
Advertisement
hi
im trying to write a java program that produce results like this
c:\> java Calc

*
8
9

72

%
5
8

5

\
99
8

Unknown operation: \
Enter 'e' to quit.

/
99
8

12

e

c:\>

------
NOW I WrOTE THIS PROGRAM BUT I CANT TERMINATE THE LOOP PLS CAN SOME ONE HELP
THANX

HERE IS THE PROGRAM


code:
import printer.*; //this is java package i am using
public class Calc
{
public static void main (String[] args)
{
boolean done = false;
char operand;

while(!done)
{
System.out.println("Please enter the operation you wish to perform:");
System.out.println(" (+) for Addition");
System.out.println(" (-) for Subtraction");
System.out.println(" (*) for Multiplication");
System.out.println(" (/) for Division");

operand = printer.readChar();
printer.println("-");
int a = printer.println.readInt();
printer.println("-");
int b = printer.readInt();
printer.println("- \n");

if (operand=='*')
{
printer.println(a*b);

else if (operand=='+')
{
printer.println(a+b);
}
else if (operand=='e')
{
//some cose to exit without errors
}
else
{
printer.println("Invalid input!");
printer.println("Enter 'e' to quit.");
}
}
}


i need to exit from the loop without errors im trying but i have no luck, i need to enter e in order to end the program.


Don Hill

Posts: 70
Nickname: ssswdon
Registered: Jul, 2002

Re: need help please Posted: Oct 11, 2002 7:14 AM
Reply to this message Reply
why not this,

else if (operand=='e')
{
//some cose to exit without errors
break; // or done = true;
}


> hi
> im trying to write a java program that produce
> results like this
> c:\> java Calc
>
> *
> 8
> 9
>
> 72
>
> %
> 5
> 8
>
> 5
>
> \
> 99
> 8
>
> Unknown operation: \
> Enter 'e' to quit.
>
> /
> 99
> 8
>
> 12
>
> e
>
> c:\>
>
> ------
> NOW I WrOTE THIS PROGRAM BUT I CANT TERMINATE THE
> LOOP PLS CAN SOME ONE HELP
> THANX
>
> HERE IS THE PROGRAM
>
>
> code:
> import printer.*; //this is java package i am using
> public class Calc
> {
> public static void main (String[] args)
> {
> boolean done = false;
> char operand;
>
> while(!done)
> {
> System.out.println("Please enter the operation you
> wish to perform:");
> System.out.println(" (+) for Addition");
> System.out.println(" (-) for Subtraction");
> System.out.println(" (*) for Multiplication");
> System.out.println(" (/) for Division");
>
> operand = printer.readChar();
> printer.println("-");
> int a = printer.println.readInt();
> printer.println("-");
> int b = printer.readInt();
> printer.println("- \n");
>
> if (operand=='*')
> {
> printer.println(a*b);
>
> else if (operand=='+')
> {
> printer.println(a+b);
> }
> else if (operand=='e')
> {
> //some cose to exit without errors
> }
> else
> {
> printer.println("Invalid input!");
> printer.println("Enter 'e' to quit.");
> }
> }
> }
>
>
> i need to exit from the loop without errors im trying
> but i have no luck, i need to enter e in order to end
> the program.

hyderman

Posts: 11
Nickname: salem99
Registered: Oct, 2002

Re: need help please Posted: Oct 11, 2002 7:15 PM
Reply to this message Reply
still gives me error.

Flat View: This topic has 2 replies on 1 page
Topic: Displaying pdf files in Java application Previous Topic   Next Topic Topic: Invalid authorization specification: Access denied for user

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use