-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Any input base to decimal number conversion
- Loading branch information
1 parent
f7a9439
commit 4a86fa8
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |