Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. package dip107;
  2. import java.util.Scanner;
  3. public class Ld2_02_191RDC038
  4. {
  5.  
  6.     public static void main(String[] args)
  7.     {
  8.         Scanner sc = new Scanner(System.in);
  9.         float x=0;
  10.         double res;
  11.         int i=1;
  12.         double a=1,s=0;
  13.         float k=-1;
  14.         int j=2;
  15.         System.out.println("2.var");
  16.         System.out.println("191RDC038 Niks Veinbergs 1");
  17.         System.out.println("181REB393 Edvards Siliņš 2");
  18.         System.out.println("Vertiba x=");
  19.         if (sc.hasNextFloat())
  20.         {
  21.         x = sc.nextFloat();
  22.         }
  23.         System.out.println("result:");
  24.         if(x>=-2&&x<=-1)
  25.         {   while(Math.abs(a) > 0.001)
  26.             {
  27.                 a=k*Math.pow(1+x,j)/i;
  28.                 s=a+s;
  29.                 i=i+1;
  30.                 j=j+2;
  31.                 k=-k;
  32.             }
  33.             res=Math.log(1/(2+2*x+x*x));
  34.             System.out.printf("function=%.4f",res);
  35.             System.out.printf("\nsumma=%.4f",s);
  36.         }
  37.         else
  38.         {
  39.             System.out.println("error");
  40.         }
  41.  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement