본문 바로가기

Java

자바의신 ch19 & ch20

package d.lang;

public class NumberObjects {
  public static void main(String[] args) {
    NumberObjects sample = new NumberObjects();
    sample.parseLong("r1024");
    sample.printOtherBase(1024L);
  }
  public long parseLong(String data) {
      try{
      return Long.parseLong(data);} catch(NumberFormatException e) {
        System.out.println(e + " is not a number");
        return -1;
      }
 }
 public void printOtherBase(long value) {
   System.out.println("Original:"+value);
   System.out.println("Binary  :"+Long.toBinaryString(value));
   System.out.println("Hex     :"+Long.toHexString(value));
   System.out.println("Octal   :"+Long.toOctalString(value));
 }

}

 

 

'Java' 카테고리의 다른 글

자바의 신 CH22 & CH23  (0) 2022.07.05
자바의신 ch21  (0) 2022.07.04
자바의 신 ch16 & ch17& ch18  (0) 2022.06.22
자바의신 ch14 & ch15  (0) 2022.06.19
자바의 신 ch 13  (0) 2022.06.16