Write a Java program to convert a decimal number to octal numberInput Data:Input a Decimal Number: 15Expected Output
Octal number is: 17
import java.util.Scanner; public class Exercise21 { public static void main(String args[]) { int dec_num, rem, quot, i=1, j; int oct_num[] = new int[100]; Scanner scan = new Scanner(System.in); System.out.print("Input a Decimal Number: "); dec_num = scan.nextInt(); quot = dec_num; while(quot != 0) { oct_num[i++] = quot%8; quot = quot/8; } System.out.print("Octal number is: "); for(j=i-1; j>0; j--) { System.out.print(oct_num[j]); } System.out.print("\n"); } }
Sample Output:
Input a Decimal Number: 15 Octal number is: 17
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer