# Java programming, need some help.



## Whizkid595 (Sep 21, 2011)

Hi all,

I am currently learning java language through the book "blue pelican" by Charles Cook, and have run into a problem with the project "Mixed Results" from lesson five.

The project is:

Create a new project called MixedResults with a class called Tester. Within the main method
of Tester you will eventually printout the result of the following problems. However, you
should first calculate by hand what you expect the answers to be. For example, in the
parenthesis of the first problem, you should realize that strictly integer arithmetic is taking
place that results in a value of 0 for the parenthesis.


double d1 = 37.9; //Initialize these variables at the top of your program
double d2 = 1004.128;
int i1 = 12;
int i2 = 18;
Problem 1: 57.2 * (i1 / i2) +1
Problem 2: 57.2 * ( (double)i1 / i2 ) + 1
Problem 3: 15 – i1 * ( d1 * 3) + 4
Problem 4: 15 – i1 * (int)( d1 * 3) + 4
Problem 5: 15 – i1 * ( (int)d1 * 3) + 4



Your printout should look like the following:
Problem 1: 1.0
Problem 2: 39.13333333333333
Problem 3: -1345.39999999999
Problem 4: -1337
Problem 5: -1313

The problem i am having is that i dont know how to get the questions to compile properly.

Here is what i have tried so far, can someone correct me and explain what i am doing wrong?
System.out.println(57.2 * (i1 / i2) +1);
x = 57.2 * (i1 / i2) +1;

I can not even get the correct answer on my calculator!


----------



## Special2God (Oct 5, 2009)

Everything appears to be working correctly... 
What compile error(s) are you getting? 

I tried this code and it worked fine:

```
public static void main(String[] args) {
	double d1 = 37.9; //Initialize these variables at the top of your program
	double d2 = 1004.128;
	int i1 = 12;
	int i2 = 18;

	System.out.println("-Problem 1: " + (57.2 * (i1 / i2) +1) );
	System.out.println("=Problem 1: 1.0");
	System.out.println("-Problem 2: " + (57.2 * ( (double)i1 / i2 ) + 1) );
	System.out.println("=Problem 2: 39.13333333333333");
	System.out.println("-Problem 3: " + (15 - i1 * ( d1 * 3) + 4) );
	System.out.println("=Problem 3: -1345.39999999999");
	System.out.println("-Problem 4: " + (15 - i1 * (int)( d1 * 3) + 4) );
	System.out.println("=Problem 4: -1337");
	System.out.println("-Problem 5: " + (15 - i1 * ( (int)d1 * 3) + 4) );
	System.out.println("=Problem 5: -1313");
}
```


----------

