mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-15 01:40:49 +08:00
Change project structure to a Maven Java project + Refactor (#2816)
This commit is contained in:

committed by
GitHub

parent
8e533d2617
commit
9fb3364ccc
30
src/main/java/com/thealgorithms/conversions/AnytoAny.java
Normal file
30
src/main/java/com/thealgorithms/conversions/AnytoAny.java
Normal file
@ -0,0 +1,30 @@
|
||||
package com.thealgorithms.conversions;
|
||||
|
||||
import java.util.Scanner;
|
||||
// given a source number , source base, destination base, this code can give you the destination
|
||||
// number.
|
||||
// sn ,sb,db ---> ()dn . this is what we have to do .
|
||||
|
||||
public class AnytoAny {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scn = new Scanner(System.in);
|
||||
int sn = scn.nextInt();
|
||||
int sb = scn.nextInt();
|
||||
int db = scn.nextInt();
|
||||
int m = 1, dec = 0, dn = 0;
|
||||
while (sn != 0) {
|
||||
dec = dec + (sn % 10) * m;
|
||||
m *= sb;
|
||||
sn /= 10;
|
||||
}
|
||||
m = 1;
|
||||
while (dec != 0) {
|
||||
dn = dn + (dec % db) * m;
|
||||
m *= 10;
|
||||
dec /= db;
|
||||
}
|
||||
System.out.println(dn);
|
||||
scn.close();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user