Directory
1 Problem Description
2 Solutions
1 problem description
Write a function that converts a decimal number to its corresponding octal number. The program reads in a decimal number, calls the function to implement the number conversion, the output corresponding octal.
Sample input
9274
Sample output
22072 Sample Input
18
Sample output
22
2 Solutions
The specific code is as follows:
Importjava.util.ArrayList;ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {ArrayList<Long> list =NewArraylist<long>(); Scanner in=NewScanner (system.in); Longn =In.nextlong (); while(N > 0) { LongTEMP = n 2; N= N/2; List.add (temp); } intLen =list.size (); if(len% 3 = = 1) {List.add (0L); List.add (0L); } Else if(len% 3 = = 2) {List.add (0L); } Len= List.size ()/3; Long[] result =New Long[Len]; intCount = 0; for(inti = List.size ()-1;i >= 0;i = i-3) { LongA = List.get (i) * 2 * 2; Longb = List.get (i-1) * 2; Longc = List.get (i-2); Result[count+ +] = a + B +C; } for(inti = 0;i < result.length;i++) System.out.print (Result[i]); }}
Algorithm Note _161: Algorithm increases decimal number to octal number (Java)