Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.PrintWriter;
- import java.io.File;
- public class PlotPolynomial
- {
- public static double calValue(double[] values, double raw, int degree)
- {
- double result = 0;
- for (int q = degree ; q >= 0 ; q--)
- {
- result += values[degree-q] * Math.pow(raw, q);
- }
- return result;
- }
- public static void main (String [] args) throws Exception
- {
- Scanner in = new Scanner(System.in);
- File f = new File ("plot.txt");
- PrintWriter pw = new PrintWriter(f);
- int count = Integer.parseInt(in.next());
- double [] values = new double [count+1];
- for (int q = 0 ; q < values.length ; q++)
- {
- values[q] = Double.parseDouble(in.next());
- }
- pw.println(" x\t f(x)");
- for (double p = -10 ; p != 10.5 ; p += 0.5)
- {
- double result = calValue(values, p, count);
- String v = String.valueOf(p);
- if (v.charAt(v.length()-1) == '0') v = v.substring(0, v.length()-2);
- pw.printf("%4s\t%.2f", v, result);
- pw.println();
- }
- pw.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement