九进制转10进制

//第一种 运用循环

public class Main {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

//在此输入您的代码...

int num=scan.nextInt();

int result=0;

int p=1;

while(num>0)

{

int n=num%10;

result+=n*p;

num=num/10;

p=p*9;

}

System.out.print(result);

scan.close();

}

}

//第二种 运用 Integer

//Integer.parseInt(String s,int radix):将指定进制的字符串转换为int类型的整数

复制代码
//Integer.parseInt(字符串,这个字符串是几进制);
import java.util.Scanner;
public class Main{
    public static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);

      String num=scan.nextLine();
      int number=Integer.parseInt(num,9);
      System.out.println(number);
    }
}

//扩充: Integer.toString(int i,int radix):将整数转换为指定进制的字符串表示

int num=255;

String number=Integer.toSting(num,2);//将num转换为二进制,并用字符串表示

相关推荐
java1234_小锋5 小时前
Java高频面试题:MyISAM索引与InnoDB索引的区别?
java·开发语言
2501_944525546 小时前
Flutter for OpenHarmony 个人理财管理App实战 - 支出分析页面
android·开发语言·前端·javascript·flutter
Mr_Xuhhh6 小时前
MySQL函数详解:日期、字符串、数学及其他常用函数
java·数据库·sql
qq_417129256 小时前
C++中的桥接模式变体
开发语言·c++·算法
开源技术6 小时前
如何将本地LLM模型与Ollama和Python集成
开发语言·python
Hello World . .6 小时前
数据结构:队列
c语言·开发语言·数据结构·vim
clever1016 小时前
在QtCreator 4.10.2中调试qt程序qDebug()输出中文为乱码问题的解决
开发语言·qt
测试开发Kevin7 小时前
小tip:换行符CRLF 和 LF 的区别以及二者在实际项目中的影响
java·开发语言·python
笨手笨脚の7 小时前
Redis: Thread limit exceeded replacing blocked worker
java·redis·forkjoin·thread limit
Lenyiin7 小时前
Linux 基础IO
java·linux·服务器