Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class Kek
- {
- public static void main(String args[]) throws IOException
- {
- Scanner in = new Scanner(new FileInputStream("in"));
- StringBuilder r = new StringBuilder();
- BigDecimal num;
- while(true)
- {
- try
- {
- String s = in.nextLine();
- if (s.equals("#"))
- {
- System.out.println(r);
- return;
- }
- int ind = s.indexOf('.');
- if (ind == s.length() - 1 || Character.toLowerCase(s.charAt(ind + 1)) == 'e')
- throw new NumberFormatException();
- num = new BigDecimal(s);
- }
- catch (NumberFormatException e)
- {
- r.append("Not a floating point number\n");
- in.nextLine();
- continue;
- }
- int n = Integer.parseInt(in.nextLine());
- DecimalFormat f = new DecimalFormat("#.#");
- f.setRoundingMode(RoundingMode.DOWN);
- f.setMinimumFractionDigits(n);
- f.setMaximumFractionDigits(n);
- StringBuilder out = new StringBuilder(f.format(num));
- if (out.toString().equals("-0,0"))
- out = new StringBuilder("0,0");
- int ind = out.indexOf(",");
- if (ind != -1)
- out.setCharAt(ind, '.');
- r.append(out + "\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement