Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class NewMain {
  5.  
  6. public static void main(String[] args) {
  7. Scanner in = new Scanner(System.in);
  8. Double x = in.nextDouble();
  9. int podstawa = in.nextInt();
  10. int calkowita = x.intValue();
  11. double ulamkowa = x - calkowita;
  12. String wyjscie = "";
  13. while (calkowita > 0) {
  14. wyjscie += calkowita % podstawa;
  15. calkowita /= podstawa;
  16.  
  17. }
  18. StringBuffer sb = new StringBuffer(wyjscie);
  19. sb.reverse();
  20. wyjscie = sb.toString() + ".";
  21. while (ulamkowa != 0) {
  22. ulamkowa = ulamkowa * podstawa;
  23. int coDodac = (int) (ulamkowa % podstawa);
  24. wyjscie += coDodac;
  25. ulamkowa -= coDodac;
  26. }
  27. System.out.println(wyjscie);
  28. }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement