[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

Learning I/O

I am trying to write a practice code that asks for the user to input numbers, it complies fine but when it runs and a number is put in it terminates:
Import java.io.*;
class  first {
      public static void main (String [] args )throws IOException{
BufferedReader in = new BufferedReader(
    new InputStreamReader(System.in));
       int Length,Width, Area;
         System.out.print ("enter Length:");
                  Length = Integer.parseInt (stdin.readLine());
         System.out.print("Enter Width:" );
                  Width = Integer.parseInt (stdin.readLine());
         System.out.println ("Area =" + (Length*Width));
}

}

What am doing wrong?

0
danmatt
Asked:
danmatt
  • 3
  • 2
1 Solution
 
hilitCommented:
danmatt,
several comments (relevant only if this is the exact code):
1. You didn't define stdin (called it "in")

2. should be import and not Import (no capital letter)

I ran it with these 2 corrections and it ran okay.
Good luck!

Hilit
0
 
danmattAuthor Commented:
We fixed those errors.  Those were just typos when we sent to you.  It compiles fine, but doesn't run.  As soon as you enter the length you get:
Interrupted!
Process completed with exit code -1.

See below corrected code:

import java.io.*;
class  first {
      public static void main (String [] args ) throws IOException {
                BufferedReader stdin = new BufferedReader
                   (new InputStreamReader(System.in));
       int Length, Width, Area;
         System.out.print ("enter Length:");
                  Length = Integer.parseInt (stdin.readLine());
         System.out.print("Enter Width:" );
                  Width = Integer.parseInt (stdin.readLine());
         System.out.println ("Area =" + (Length*Width));
   }
   }

0
 
hilitCommented:
so? did it help or not?

Hilit
0
 
danmattAuthor Commented:
It fixed the problem in the listed code.  However, the main problem was we were using "Textpad" as our editor.  When running the application, the preference box was checked "capture output".  Once this box was unchecked, it worked.  We tried to do it in dos, and there the problem was we compiled in text pad and ran in dos.  When we compiled in dos edit program and ran it worked fine.  So bottom line we had several problems.
0
 
hilitCommented:
Again, the simplest solution turns out to be the best...
Regards,
Hilit
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now