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
google-chrome
jms
haproxy
tcsh
dafny
braintree
google-play-services
elisp
cypher
ipv6
tup
cocotb
gtk
elastic-load-balancer
sap-fiori
squirrel-sql
jodatime
distributed-computing
squid
global-variables
twisted
c#-7.0
significance
nullreferenceexception
yii2-basic-app
dashdb
hdl
vuforia
function-points
python-appium
math.js
adapter
sales
region
snap-framework
shapeless
advanced-filter
spring-rabbitmq
nppexec
nsuserdefaults
love2d
linq.js
windows-store
permission-denied
nuclio
intellij-lombok-plugin
swift2.3
icecast
scala-breeze
uiautomatorviewer
nusoap
lightning-workbench
test-data
mobile-angular-ui
lvalue
word-2016
sidewaffle
http4s
email-injection
allegro
streamwriter
clp
traversable
android-sdcard
piping
noclassdeffounderror
apple-configurator
django-redis
currency-exchange-rates
wif4.5
m4
uitest
html-escape-characters
mod-auth-openidc
sql-processor
juttle
webautomation
screwturn
boolean-algebra
assetic
lsa
spring-security-acl
facebook-game-groups
apache-shindig
statechart
chefspec
django-filebrowser
clrprofiler
hardcode
exponent
acpi
gwt-celltable
zend-server-ce
django-apps
servercontrol
data-dump
resharper-5.1
subtext
xap
jvm-bytecode
error-detection

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App