Scala Program to Print the Hexadecimal & Octal value of the number

How to print the hexadecimal and octal value of any number in Scala Programming. Here, I am sharing the source code to print hexadecimal numbers and decimal values of any given number.

Scala Program to print Hexadecimal and Octal values of number

object divineseo{
    def main(arg: Array[String]){
        val number:Int = 15
        printf("Decimal Value: %d\n", number)
        printf("Hex Value: %x\n", number)
        printf("Octal Value: %o\n", number)

First, we declare a variable number and assign it to the value 15. Here we use %x which is used to print the hexadecimal value of any given number. Similarly, %o is used to print the octal value to the console screen.


Decimal Value: 15
Hex Value: f
Octal Value: 17

As you can see, here the hex value of 15 is ‘f’ and the octal value of 15 is 17.

Leave a Comment