From b5642771a07e80b143e6626ed4d2ad4ebf4855a2 Mon Sep 17 00:00:00 2001 From: Vedanth Baliga <44313631+vedanthv@users.noreply.github.com> Date: Thu, 1 Oct 2020 14:21:24 +0530 Subject: [PATCH] Added Dec_To_Base Solution --- .../Functions and Arrays/Dec_To_Base.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Pepcoding/Foundation/Functions and Arrays/Dec_To_Base.java diff --git a/Pepcoding/Foundation/Functions and Arrays/Dec_To_Base.java b/Pepcoding/Foundation/Functions and Arrays/Dec_To_Base.java new file mode 100644 index 0000000..44d876d --- /dev/null +++ b/Pepcoding/Foundation/Functions and Arrays/Dec_To_Base.java @@ -0,0 +1,26 @@ +import java.util.*; + + public class Main{ + + public static void main(String[] args) { + Scanner scn = new Scanner(System.in); + int n = scn.nextInt(); + int b = scn.nextInt(); + int dn = getValueInBase(n, b); + System.out.println(dn); + } + + public static int getValueInBase(int n, int b){ + int rv = 0; + + int p = 1; + while(n > 0){ + int d = n % b; + n = n / b; + rv += p * d; + p = p * 10; + } + + return rv; + } + }