fork(3) download
  1. public class Main {
  2.  
  3. public static void main(String args[]) {
  4. System.out.println(abreviarComK(1000));
  5. System.out.println(abreviarComK(2000));
  6. System.out.println(abreviarComK(10000));
  7. System.out.println(abreviarComK(300));
  8.  
  9. }
  10.  
  11.  
  12. public static String abreviarComK(long numero) {
  13.  
  14. if (numero < 1000) {
  15. return Long.toString(numero);
  16. } else {
  17. return (numero/1000.0 + "k").replace(".", ",");
  18. }
  19.  
  20. }
  21.  
  22. }
Success #stdin #stdout 0.1s 27996KB
stdin
Standard input is empty
stdout
1,0k
2,0k
10,0k
300