(Coderbyte) Division Stringified - Solução

Have the function DivisionStringified(num1,num2) take both parameters being passed, divide num1 by num2, and return the result as a string with properly formatted commas. If an answer is only 3 digits long, return the number with no commas (ie. 2 / 3 should output "1"). For example: if num1 is 123456789 and num2 is 10000 the output should be "12,345".

Solução:

import java.util.*;
import java.io.*;
import java.lang.*;
import java.text.*;

class Function { 
  String DivisionStringified(int num1, int num2) {
      double divisao = Math.round((double)num1/num2);

    DecimalFormat df = new DecimalFormat(",##0");
   
    return df.format(divisao);     
  }
 
  public static void main (String[] args) { 
    // keep this function call here    
    Scanner  s = new Scanner(System.in);
    Function c = new Function();
    System.out.print(c.DivisionStringified(s.nextLine()));
  }  
 
}          

Comments

Popular posts from this blog

(Coderbyte) Powers of Two - Solução

(Coderbyte) Dash Insert II - Solução

(CoderByte) Number Search - Solução