前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >鸿蒙原生素数库发布

鸿蒙原生素数库发布

作者头像
徐建国
发布2025-01-13 12:43:17
发布2025-01-13 12:43:17
5900
代码可运行
举报
文章被收录于专栏:个人路线个人路线
运行总次数:0
代码可运行

用于判断一个数是否是素数(也称为质数)

使用方法

代码语言:javascript
代码运行次数:0
运行
复制
ohpm install @nutpi/isprime

示例

代码语言:javascript
代码运行次数:0
运行
复制
import { isPrime } from "@nutpi/isprime"

@Entry
@Component
struct Index {
  @State message: string = '请输入数字';
  @State currentNum: number = 11;
  @State res: string = '';

  build() {
    Column({space: 20}) {
      Text(this.message)
        .fontSize(20)
        .fontWeight(FontWeight.Bold)
      TextInput({text: this.currentNum.toString()})
        .type(InputType.Number)
        .onChange((value: string) => {
          this.currentNum = Number(value)
        })

      Button('计算')
        .width('80%')
        .onClick(() => {
        let result = isPrime(this.currentNum) ? '是素数':'不是素数';
        console.info(result); // 输出: true
        this.res = result
      })
      Text(this.res)
        .fontSize(20)
        .fontWeight(FontWeight.Bold)

    }
    .height('100%')
    .width('100%')
    .justifyContent(FlexAlign.Center)
  }
}

效果图

官网

https://www.nutpi.net/

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2025-01-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 大前端之旅 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 使用方法
  • 示例
  • 效果图
  • 官网
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档