您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)


Extend Index

Extend Page # 18

Listing of Exception2.java

import javax.swing.*;

public class Exception2

{

public static void main( String args[] )

{

String ageString;

int age;

System.out.println("Age parsing application");

ageString = JOptionPane.showInputDialog(null, "Enter age (1-100)", "Entry of age",

JOptionPane.QUESTION_MESSAGE);

try

{

age = Integer.parseInt( ageString );

int ageNextBirthday = (age + 1);

System.out.println("Age now : " + age);

System.out.println("Age next birthday: " + ageNextBirthday);

}

catch (NumberFormatException n)

{

System.out.println("sorry - your age entry of ‘" + ageString + "‘ is not

a valid integer");

}

System.exit(0);

}

} // class

Back to top

 basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg