Java String Divide divide(String type)

Here you can find the source of divide(String type)

Description

divide

License

Open Source License

Declaration

public static String divide(String type) 

Method Source Code

//package com.java2s;

public class Main {
    public static String divide(String type) {
        try {//from ww  w  .  j  a va2 s . c  om
            String[] operands = type.split("/");
            double operand1 = Double.parseDouble(operands[0]);
            double operand2 = Double.parseDouble(operands[1]);
            double ans = operand1 / operand2;
            return Double.toString(ans);
        } catch (NumberFormatException e) {
            return type;
        }
    }
}

Related

  1. divide(final String s)
  2. divide(Object o1, Object o2, String type)
  3. divide(String m)
  4. divide(String str, char c)
  5. divide(String ts, String ms)
  6. divideFullName(final String fullName)