Skip to content

Commit

Permalink
Any input base to decimal number conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
suhanigupta23 authored Feb 4, 2024
1 parent f7a9439 commit 4a86fa8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions any_base_to_decimalconversion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.util.*;
public class Program
{
public static void main(String[] args)
{
//Conversion of other base to decimal
//taking input of number n in base b
//and converting it to number of base decimal
Scanner scn=new Scanner(System.in);
int n=scn.nextInt();
int b=scn.nextInt();
int decimal_number=0;
int count=0;
while(n!=0)
{
int rem=n%10;
int mult=(int)Math.pow(b,count);
int fin=rem*mult;
decimal_number=decimal_number+fin;
count++;
n=n/10;
}
System.out.println(decimal_number);
}
}

0 comments on commit 4a86fa8

Please sign in to comment.