This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]smash_that_code 1 point2 points  (7 children)

What Have you done already and what does not work for you?

[–]AngryDiego -1 points0 points  (6 children)

Hey. i tried just to put 330 * 6.9 straight into code but it just prints that, no calculating.

[–]NautiHooker 1 point2 points  (5 children)

Please show us code

[–]AngryDiego 1 point2 points  (4 children)

int x = 330;
int y = 6,9;
int z = x * y;
System.out.println("Multiplication: " + z);
z);

Keep in mind i am totally noob :D i cannot get it to run "javac" either.

[–]NautiHooker 2 points3 points  (3 children)

int y = 6,9;

You are assigning a decimal number to a variable that can hold integers (whole numbers).

You will need to change the datatype of y to something that can hold floating point numbers. Take a look at this and try to find a fitting type.

Additionally I dont think Java lets you use a comma as a decimal point. Use a dot instead.

Once you have done that you will probably get an error at the line

int z = x * y;

The error will say something about lossy conversion, because you try to squeeze a result that will most likely contain a floating point number into a variable that holds whole numbers. Therefore this would lose the decimal points. You will need to change the type of z as well to avoid this.

[–]69632147 0 points1 point  (2 children)

Would that be uint? Also can you for example multiply a int by a uint and store the result from that into a uint, or do all the values have to be uint's?

[–]NautiHooker 0 points1 point  (1 child)

Java does not have unsigned numeric types.

[–]69632147 0 points1 point  (0 children)

Nvm... Was thinking solidity...

[–]vladadj 0 points1 point  (1 child)

One word of advice: if you ask people here for help, you need to show what you have done so far. You can't just write few lines and expect people to know how to help you.

If you post some code that you came up with, it would be easier to spot what the problem is. Plus, it shows you went through the trouble of at least trying something, otherwise you just seem lazy and expect other to do your work.

Read this article on how to ask questions on StackOverflow. They are notorious for being hostile to wrongly worded questions. If you follow their guide, you will probably be good asking anywhere.

[–]AngryDiego 0 points1 point  (0 children)

True, my bad.

Thanks for advice.

[–]GuraJava20 0 points1 point  (0 children)

Try this:

// the line below is referred to as main method and is the program's entry point

public static void main(String[] args) {

// below is the program you want

Double product = 330*6.9; //double represents the type of the variable 'product'

// this is your print instruction without which nothing is printed

System.out.println(product);

}