Thursday, November 15, 2012

Essential Java Key Knowledge Points

1.  The essential benefit of exception handling is to separate the detection of an error (done in a called method) from the handling of an error (done in the calling method).
2. int -> String
...
int number = 1;
String s = Integer.toString(s);
...
  String -> int
method 1: //this one is better because you can make sure what you input is an Int type.
int number ;
String s = "1";
Scanner sc = new Scanner(number);
if(sc.hasNextInt()) number = sc.nextInt();
method 2: 


int number ;
String s = "1";

number= Integer.parseInt(number);

No comments:

Post a Comment