Pages

සීමාවන් නොමැති අදහස් වලට පණ දෙන්න.....

Tuesday, October 6, 2009

a program that would read a number and the base of the number system and print the equivalent decimal value ( for many bases) using Integer.pasrseInt

a program that would read a number and the base of the number system
and print the equivalent decimal value ( for many bases ) using Integer.pasrseInt

01# import java.util.Scanner;
02#
03# public class javaprog{
04#
05# public static void main(String[] args){
06#
07# System.out.println("\n\n\tProgram using Integer.parseInt \n");
08# System.out.println("\t tested with many digits and bases like base 2 to base 10 and base 16 \n");
09#
10# //ask the value to convert
11# System.out.print("Enter the value which you want to convert in to decimal:");
12# Scanner parseint = new Scanner(System.in);
13# String parseintVal=parseint.next();
14#
15# //ask for the base of the value which enterd
16# System.out.print("\nEnter the base of the value which you entered first:");
17# Scanner parseintScan = new Scanner(System.in);
18# int parseintBase = parseintScan.nextInt();
19#
20# //calculation using Integer.parseInt
21# int i= Integer.parseInt(parseintVal,parseintBase);
22#
23# //prints the decimal value
24# System.out.println("\n\t Decimal Value of " +parseintVal+ " ( base "+ parseintBase+ " ) is "+i+"\n");
25#
26# }
27# }
28#


output:
Program using Integer.parseInt
tested with many digits and bases like base 2 to base 10 and base 16
Enter the value which you want to convert in to decimal:123ACD
Enter the base of the value which you entered first:16
Decimal Value of 123ACD ( base 16 ) is 1194701

No comments:

Post a Comment

හිත කියන්නෙ පුදුම දෙයක්. ඒක තියෙන්නෙ කොතැනද කියලා කවුද දන්නෙ?
හිත නිතරම වෙනස් වෙනවා. හිතට නිතරම සිතුවිලි එනවා.
හිතට වරක් ආපු සිතුවිල්ලක් නැවත ඇති වෙන්නෙ කලාතුරකින්.

ඔබ කැමති නම් හිතට එන සිතුවිලි/අදහස් අකුරු කරන්න.


ඇනෝලා සමා වෙත්වා. මගේ බ්ලොග් එකට ස්පෑම්බොට් එකකින් ස්පෑම් කමෙන්ට් එනනිසා ඇනෝලාගේ කමෙන්ට් කිරීමේ අයිතිය නැති කරන්න සිදු වුනා.

Related Posts with Thumbnails