Java中的Integer.toOctalString()方法将int转换为八进制字符串。
假设以下是我们的整数值。
int val1 = 9; int val2 = 20; int val3 = 2;
将上述int值转换为八进制字符串。
Integer.toOctalString(val1); Integer.toOctalString(val2); Integer.toOctalString(val3);
public class Demo { public static void main(String[] args) { int val1 = 9; int val2 = 20; int val3 = 30; int val4 = 78; int val5 = 2; System.out.println("Converting integer "+val1+" to Octal String: "+Integer.toOctalString(val1)); System.out.println("Converting integer "+val2+" to Octal String: "+Integer.toOctalString(val2)); System.out.println("Converting integer "+val3+" to Octal String: "+Integer.toOctalString(val3)); System.out.println("Converting integer "+val4+" to Octal String: "+Integer.toOctalString(val4)); System.out.println("Converting integer "+val5+" to Octal String: "+Integer.toOctalString(val5)); } }
输出结果
Converting integer 9 to Octal String: 11 Converting integer 20 to Octal String: 24 Converting integer 30 to Octal String: 36 Converting integer 78 to Octal String: 116 Converting integer 2 to Octal String: 2