write a program that will convert a decimal number to octal
Purpose: In this the number that we are entering will be a decimal number and from this the output number that is been produced must be the octal number and the code is as given below
Code:
import java.util.Scanner;
//main function
class Main
{
public static void main(String args[])
{
//new object is been created
Scanner input = new Scanner( System.in );
//this will be printted
System.out.print("Enter a decimal number : ");
int num =input.nextInt();
/* in this we will be using the predefined method toOctalString(int) and then Pass the decimal number to this method and
* and it will return the equivalent octal number
*/
String octalString = Integer.toOctalString(num);
//this will be printed
System.out.println("octal value: " + octalString);
}
}
Step by step
Solved in 2 steps with 1 images