zx-coder
  • 生成一个随机100内小数,转换为保留两位小数的字符串,不考虑四舍五入的问题。

  • 参考答案:

		public class Test5 {
		    public static void main(String[] args) {
		        double random = Math.random()*100;
		        System.out.println("随机数为:");
		        System.out.println(random);
		        String str = random+"";
		        int index = str.indexOf(".");
		        //System.out.println(index);
		        String substring = str.substring(0, index + 3);
		        System.out.println("转换为:");
		        System.out.println(substring);
		    }
		}

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-01-29
  • 2021-12-20
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
猜你喜欢
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案