OneCompiler

read an int from user and convert it to binary and octal

293

Q6 Write a program to read an integer from user and convert it to binary and octal using user defined functions.?
object demo
{
def octal(num:Int) :Unit=
{
printf("Octal value: %o\n", num)
}
def main(args:Array[String])
{
print("Enter the Number = ")
var num = scala.io.StdIn.readInt()

		var binary = (num).toBinaryString
		
		println("Binary of "+num+" is "+binary)
		
		octal(num);
	}
}