Advertisement
Guest User

lab3

a guest
Oct 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. import java.util.Scanner;
  2. class Lab3{
  3.     public static void main(String [] args){
  4.  
  5.             Scanner sc = new Scanner(System.in);
  6.             int x,x2,x3;
  7.             double result,result2,result3;
  8.  
  9.             System.out.println("Please enter the value of x");
  10.             x = sc.nextInt();
  11.  
  12.             x2=x-1;
  13.             x3=x+1;
  14.  
  15.             result = (x*x*x-4*(x+20))/2.0;
  16.             result2= (x2*x2*x2-4*(x2+20))/2.0;
  17.             result3= (x3*x3*x3-4*(x3+20))/2.0;
  18.  
  19.             System.out.println("F("+x+") = " + result);
  20.             System.out.println("F("+x2+") = " + result2);
  21.             System.out.println("F("+x3+") = " + result3);
  22.  
  23.             System.out.print("Thanks for using my program :)");
  24.         }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement