|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help With Basic Java(Just Starting Out)
Well, I am just starting out with learning Java, and I was doing this excercise. The point was to make a program that
class Example4 { public static void main ( String[] args ) { double x, value; x = 2/3 ; System.out.println("Answer is:" + (3*(x*x)- 8*x + 4)); } } Now, the next excercise says this: Modify the program in exercise 2 so that one run of the program will evaluate and write out the value of the quadradic for three different values of X: 0.0, 2.0, and 4.0 (or any three values of your choice.) Write the program using only two variables, probably called x and value. Of course this means that you will have to put different things in these variables in different places in the program. Now I have no idea how to do this. Can anyone help me out. Thanks. |
|
#2
|
|||
|
|||
|
I would advise you to start by making a function that computes the quadratic based on any given input for x and returns the answer. Then call that function with your values asigning the answer to value after each and printing it.
-KM- |
|
#3
|
|||
|
|||
|
class Example4
{ public static void main ( String[] args ){ System.out.println("Answer is:" + evaluate(0.0)); System.out.println("Answer is:" + evaluate(2.0)); System.out.println("Answer is:" + evaluate(4.0)); } double evaluate(double x){ return (3*(x*x) - 8*x + 4); } } _____________________________________________________ Sharon White |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Help With Basic Java(Just Starting Out) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|