• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
蜗牛的后背
博客园    首页    新随笔    联系   管理    订阅  订阅

打印出10道四则运算

我用的工具:java

    int a,b,i;
    char aa[]={'+','-','*','/'};
    for(int r=1;r<=10;r++){
    a=(int)(1+Math.random()*(999-1+1));

  //(int)(1+Math.random()*(10-1+1)) //从1到10的int型随数

    b=(int)(1+Math.random()*(999-1+1));
    i=a;
    String s=String.valueOf(a);

  //String s=String.valueOf(vale);其中 value为任意一种数字类型。
    String e=String.valueOf(b);
    System.out.print(s+aa[i%4]+e+'='+'\n');
}

补充转换类型:

  字符串转换成数字类型:

    String s="169"

    byte b=Byte.parseByte(s);

    short t= Short.parseShort(t);

    int i=Integer.parseInt(i);

    long l=Long.parseLong(l);

    float f=Float.parseFloat(f);

    double d=Double.parseFouble(d);

  数字类型余数字类型对象之间的转换:

    int=169;

    Integer io=new Integer(i);

    i=io.intValue();

 

    long l=169;

    Long lo= new Long(l);

    l=lo.longValue();

posted @ 2018-03-08 14:01  蜗牛的后背  阅读(439)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3