Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zadatak2_Polic_Samardzic;
- import java.util.Scanner;
- public class VrijednostPolinoma {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.print("Unesite broj clanova polinoma: ");
- Scanner num = new Scanner(System.in);
- int n = num.nextInt();
- float[] array = new float[n];
- for (int i = n-1; i >= 0; i--) {
- if(i == 0) System.out.print("Unesite slobodni clan: ");
- else if(i == 1) System.out.print("Unesite koeficijent uz x: ");
- else System.out.print("Unesite koeficijent uz x^" + i + ": ");
- num = new Scanner(System.in);
- array[i] = num.nextFloat();
- }
- System.out.print("Unesite tocku x: ");
- num = new Scanner(System.in);
- float x = num.nextFloat();
- float res = calculate(array, n, x);
- num.close();
- System.out.print("\n\n");
- System.out.println("Rezultat funkcije za vrijednost x = " + x + " je " + res);
- //System.out.printf("Rezultat funkcije za vrijednost x = %.2f je %.2f", x, res);
- }
- public static float calculate(float[] array, int n, float x) {
- float res = 0;
- for (int i = 0; i < n; i++) {
- res += array[i] * Math.pow(x, i);
- }
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement