472,958 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

num = Keyboard.readInt(); java

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.awt.*;
  3. import hsa.Console;
  5. public class Calculator
  6. {
  7.     static Console c;           
  9.     public static void main (String [] args) throws IOException
  11.     {
  12.         c = new Console ();
  14.         int num1, num2;
  15.         int difference, sum, product, quotant;
  16.         String awnser;
  18.         DataInputStream keyboard = new DataInputStream (System.in);
  20.         System.out.println ("Calculator Ready: enter a value");
  21.         num1 = keyboard.readInt ();
  22.         System.out.println ("Enter another value: ");
  23.         num2 = keyboard.readInt ();
  24.         System.out.println ("What would you like to do with there two values?");
  25.         System.out.println ("add, subtract, multiply or divide?");
  26.         awnser = keyboard.readLine ();
  28.         difference = num1 - num2;
  29.         sum = num1 + num2;
  30.         product = num1 * num2;
  31.         quotant = num1 / num2;
  33.         if (awnser.equals ("subtract"))
  34.         {
  35.             System.out.println (num1 + " - " + num2 + " = " + difference);
  37.         }
  38.         else if (awnser.equals ("multiply"))
  39.         {
  40.             System.out.println (num1 + " x " + num2 + " = " + product);
  42.         }
  43.         else if (awnser.equals ("divide"))
  44.         {
  45.             System.out.println (num1 + " / " + num2 + " = " + quotant);
  47.         }
  48.         else
  49.         {
  50.             System.out.println (num1 + " + " + num2 + " = " + sum);
  52.         }
This is a calculator simulation its not the whole thing but i just wanted to fix the error i am having before i move on. The language is java and the type of programs i am using are basic ones their ready anf Drjava.
The error message is:
Expand|Select|Wrap|Line Numbers
  1.  java.io.EOFException
  2.         at java.io.DataInputStream.readInt(DataInputStream.java:363)
  3.         at Calculator.main(Calculator.java:25)
Nov 20 '08 #1
1 13159
3,652 Expert 2GB
If you are using Java 1.5 or later, try the Scanner.java class instead of DataInputStream.
Nov 21 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Nicholas Pappas | last post by:
Hello all. I am trying to write a Java3D loader for a geometry file from a game, which has Unicode characters (Korean) in it. I wrote the loader and it works in Windows, but I recently brushed...
by: Rhino | last post by:
I've been playing with Java UDFs for the last couple of days and I've got some questions about scratchpads. I'm running DB2 LUW V8 (FP8) on WinXP. Somewhere in the manuals, I found some remarks...
by: RoSsIaCrIiLoIA | last post by:
I a poor beginner defy this NG to write an ANSI-C portable int readint(FILE* fp); better of my in the treatment of a stream ______________ #include <stdio.h> #include <assert.h> #include ...
by: yaron | last post by:
Hi all, i need to read a float number in my c# client that is received from a socket from a java server. 1. i think i found a sollution, here it is : public float readFloat() { return...
by: eviewcs | last post by:
Hello I am a newbie in DB2. I am trying out the Mapping Java definitions to SQL on UDT from the article "DB2's object-relational highlights: Store and invoke structured type objects" by Kathryn...
by: kaleeswaran | last post by:
hi! i tried to get the input through keyboard using keyboard.readInt() method but after compilation error shows "variable keyboard undefined" i don't know how to solve the pbm..plzz tell...
by: jopeter | last post by:
hi i have wrote this progaram in java. it finf the palidrome numbers and print it. its by threads it has some errors and i can t run it. please help me. package palindromen; import...
by: webprogramer | last post by:
Use an array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements...
by: 9107you | last post by:
I just started the course and this crazy teacher wants me to do this hard ass question The government of Mississauga has asked you to write a program that would calculate taxes for Mississauga...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.