Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. package zadatak2_Polic_Samardzic;
  2. import java.util.Scanner;
  3.  
  4. public class VrijednostPolinoma {
  5.  
  6.     public static void main(String[] args) {
  7.         // TODO Auto-generated method stub
  8.         System.out.println("Unesite broj clanova polinoma");
  9.         Scanner num = new Scanner(System.in);
  10.        
  11.         int n = num.nextInt();
  12.         float[] array = new float[n];
  13.        
  14.         for (int i = n-1; i >= 0; i--) {
  15.             if(i == 0) System.out.println("Unesite slobodni clan");
  16.             else if(i == 1) System.out.println("Unesite koeficijent uz  x");
  17.             else System.out.println("Unesite koeficijent uz  x^^" + i);
  18.             Scanner koef = new Scanner(System.in);
  19.             array[i] = koef.nextFloat();
  20.         }
  21.        
  22.         System.out.println("Unesite tocku x");
  23.         Scanner value = new Scanner(System.in);
  24.         int x = value.nextInt();
  25.         float res = calculate(array, n, x);
  26.        
  27.         num.close();
  28.         value.close();
  29.        
  30.         System.out.print("\n\n\n");
  31.         System.out.println("Rezultat funkcije za vrijednost x = " + x + " je " + res);
  32.     }
  33.  
  34.     public static float calculate(float[] array, int n, int x) {
  35.         float res = 0;
  36.         for (int i = 0; i < n; i++) {
  37.             res += array[i] * Math.pow(x, i);
  38.         }
  39.         return res;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement