ioexception


Exception in thread Main Error java.lang.numberformat.exception


I am beginner to java.Can you tell me what is the problem here.It is compiling but I a unable execute.
import java.io.*;
class rect
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int length,width,area;
length=Integer.parseInt(br.readLine());
width=Integer.parseInt(br.readLine());
area=length*width;
System.out.println("area"+area);
}
}
Error:Exception in thread Main Error java.lang.numberformat.exception :5 10
Input is not a number which cannot be parsed.
5 10 has a space in between.
The program is fine, but you seem to be using it in the wrong way. Judging from the exception, you entered 5 10 on the console for the values of length and width, but both of those variables try to parse an entire line of input. That is, the input line 10 5 is read and length=Integer.parseInt(br.readLine()); tries to parse this line as one integer number, which fails.
Instead, you should enter the two numbers separately: 10, <enter>, 5, <enter>; then it works.
Alternatively, you can enter both numbers in one line and then use String.split to split the line in two strings, both of which can then be parsed as integers.
String[] numbers = br.readLine().split(" ");
length = Integer.parseInt(numbers[0]);
width = Integer.parseInt(numbers[1]);

Related Links

java.io.IOException: Incorrect configuration: namenode address dfs.namenode.servicerpc-address or dfs.namenode.rpc-address is not configured
How to cancel request using merge
PrintWriter doesn't seem to be writing to file even though I'm closing it
StreamWriter.Writeline throws “Not enough storage is available to process this command.” IO exception
IO Exception in OSMembrane while executing pipeline
Exception in thread Main Error java.lang.numberformat.exception
java.io.IOException: The filename, directory name, or volume label syntax is incorrect Error while writing to HTTP directory

Categories

HOME
cocoapods
user-interface
xcode
openxml
eclipse-plugin
bots
ios-simulator
position
ag-grid
log4j2
amazon-emr
android-externalstorage
smartgwt
exe
multiple-tables
pfobject
android-permissions
workday
web-analytics
el
qa
android-service
onchange
annotation-processing
social-networking
progid
python-2.x
actframework
rspec-rails
kendo-listview
autoencoder
busboy
cheat-engine
extbase
suds
jacoco-maven-plugin
uipickerview
oracle-bmcs
docker-ucp
daz3d
android-5.0-lollipop
nusoap
annotatorjs
libharu
system.web.optimization
fuzzer
gcloud-node
mathml
mathnet
fdt
textblock
ioctl
ui4j
largenumber
place
sqlbase
mobilefirst-server
erlog
debug-symbols
lifetime
adhoc-polymorphism
cout
loginview
aho-corasick
category-theory
rpg
neo4jphp
fileshare
bittorrent-sync
jchartfx
compiler-flags
revmob
objective-c-runtime
examine
session-0-isolation
multiple-dispatch
image-scanner
flymake
algol68
groovy-console
firefly-mv
sql-parametrized-query
asp.net-mvc-views
nsconnection
aspbutton
ppc
jquery-effects
subtext
icon-language

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App