Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Write a program in java to evaluate and print the value of mathematical function: f(x,y) = 2x2 - y + 3

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 571
    Answer it

    Write a program in java  to evaluate and print the value of the following mathematical function:

    f(x,y) = 2x2 - y + 3

    Vary the values of x and y according to the following table and prints the values of f(x,y) as shown in the table.

    x = ( 3.0,  2.0,  -4.0)

    y = (3.0,  3.0,  2.0)

     

    Thanks

     

    Here’s what I’ve tried

    public class Example {
    
     
    
    public static void main(String[] args) {
    
                 
    
                  double z;
    
                  double x;
    
                  double y;
    
                 
    
                  z = 2*x*x - y + 3;
    
                 
    
                  x = 3.0;
    
                  y = 3.0;
    
                 
    
                  System.out.println(z);
    
                 
    
           }
    
                 
    
                 
    
    }

     

     

 1 Answer(s)

  • Hi Mark,

    You can write a separate function and call that function from your main method as below:

     

    public class CalculateFun {
    
    	public static void main(String[] args) {
    	    double x = 3.0;
    	    double y = 3.0;
    
    	    double z = f(x, y);
    
    	    System.out.println(z);
    
    	}
    
    	private static double f(double x, double y) {
    	  return 2 * x * x - y + 3; 
    	}
    }
    

     

    Hope this will help you:)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: