Home » , » penerapan isNumber() pada java

penerapan isNumber() pada java

Posted by Tutorial Programming on Kamis, 19 April 2012


package tugas;

import java.util.Scanner;

public class isnumber {

    public static void main(String args[]) {

        String in;

        System.out.print(">> ");

        Scanner input = new Scanner(System.in);

        in = input.nextLine();

        boolean num = isNum(in);

        System.out.println(num);

        if (num == true) {

            //jumlah(in);

            double x = Double.parseDouble(in);

            jumlah(x);

        } else {

            jumlah(in);

        }

       

    }



    public static boolean isNum(String s) {

        try {

            Double.parseDouble(s);

        } catch (NumberFormatException nfe) {

            return false;

        }

        return true;

    }



    public static void jumlah(double a) {

        double b;

        b = a + 10;

        System.out.println(b);

    }



    protected static void jumlah(String a) {

        int b = 10;

        System.out.println(b + a);

        

            System.out.println("bisa");

    }

}


2 comments: