poj 1001 java

來源:互聯網
上載者:User

小數的冪計算

注意

toPlainString的使用,表示非科學計數法

View Code

 1 import java.io.*;
2 import java.awt.*;
3 import java.math.*;
4 import java.text.*;
5 import java.util.*;
6
7 public class Main {
8
9 public static void main(String[] args) {
10 Scanner scan = new Scanner(new BufferedInputStream(System.in));
11 while (scan.hasNext()) {
12 BigDecimal n = scan.nextBigDecimal();
13 int d = scan.nextInt();
14 n = n.pow(d);
15 String s = new String(n.toPlainString());
16 int flag1 = 0;
17 while (s.charAt(flag1) == '0')
18 flag1++;
19 int end = s.length()-1;
20 while (s.charAt(end) == '0')
21 end--;
22 if (s.charAt(end) == '.')
23 end--;
24 for (int i = flag1; i <= end; i++)
25 System.out.print(s.charAt(i));
26 System.out.println();
27 }
28 }
29 }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.