Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

newbie: String to integer problem

0 views
Skip to first unread message

Francis Demers

unread,
Feb 19, 1997, 3:00:00 AM2/19/97
to

When i compile, there is no error message, but when i start the program,
i get this message. Following : the code... Thanks

The message :

C:\mesAppli>java arithm
Donnez une valeur au nombre entier i1 :
15
java.lang.NumberFormatException: 15
at java.lang.Integer.parseInt(Integer.java:240)
at java.lang.Integer.parseInt(Integer.java:278)
at arithm.main(arithm.java:13)

The code:
public class arithm
{
public static void main (String args[]) throws java.io.IOException
{
// Illustration des opSateurs arithmUiques
int i1, i2;
double r1, r2;
char C;
String Interm;

System.out.println("Donnez une valeur au nombre entier i1 : ");
Interm = Lit();
i1 = Integer.parseInt(Interm);
System.out.println("Donnez une valeur au nombre entier i2 : ");
Interm = Lit();
i2 = Integer.parseInt(Interm);
System.out.println(" i1 + i2 = " + (i1+i2));
System.out.println(" i1 - i2 = " + (i1-i2));
System.out.println(" i1 * i2 = " + (i1*i2));
System.out.println(" i1 / i2 = " + (i1/i2));
System.out.println(" i1 % i2 = " + (i1%i2) + "\n");
System.out.println("Donnez une valeur au nombre rFl r1 : ");
Interm=Lit();
r1 = Double.valueOf(Interm).doubleValue();
System.out.println("Donnez une valeur au nombre rFl r2 : ");
Interm=Lit();
r2 = Double.valueOf(Interm).doubleValue();
System.out.println(" r1 + r2 = " + (r1+r2));
System.out.println(" r1 - r2 = " + (r1-r2));
System.out.println(" r1 * r2 = " + (r1*r2));
System.out.println(" r1 / r2 = " + (r1/r2));
System.out.println(" r1 % r2 = " + (r1%r2) + "\n");
}
public static String Lit() throws java.io.IOException
{
// ------------------------------------------------
// Lecture d'une valeur entrF au clavier
// et renvoi de la valeur sous la forme d'un String
// ------------------------------------------------
String S = "";
char C;
while ((C=(char)System.in.read()) != '\n')
{
S = S + C;
}
return S;
}
}

0 new messages