desislava777

int ToBase

Dec 18th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6. static String IntegerToBase(int number, int ToBase)//ако ToBase е 2, числото number се обръща в двоична, 3 в троична и т. н.
  7. {
  8. String result = "";
  9. while (number>0)
  10. {
  11. int rem = number % ToBase;
  12. switch (result = rem + result) {
  13. }
  14. number /= ToBase;
  15. }
  16. return result;
  17. }
  18. public static void main(String[] args) {
  19. // write your code here
  20. Scanner scanner=new Scanner(System.in);
  21. int number=Integer.parseInt(scanner.nextLine());//числото, което се записва в друга бройна система
  22. int toBase=Integer.parseInt(scanner.nextLine());//бройната система
  23. String converted = IntegerToBase(number, toBase);//извикване на метода
  24. System.out.println(converted);
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment