Question: open a new project in NetBeans ( File , New Project ) accept defaults ( Java ) project name: division this program will take two

open a new project in NetBeans (File, New Project)
accept defaults (Java)
project name: division
this program will take two integers, divided one by the other, and display the result
enter the following command statements between the curly brackes under the main function:
output the following, by using the System.out.println(); command
"this program will take two integers, divided one by the other, and display the result"
declare two numbers as integers and assign values
number1=2
number2=3
new data type: double
used for division
used when value is a decimal
declare a double called quotient
assign quotient the expression number1/ number2
click on Save All button (if button disabled, saved automatically)
run the program; your output should look like this:
2 divided by 3 equals 0.0
------------------------------------------------------------------------
BUILD SUCCESS
the answer is wrong; yet, it says build success; huh?
the reason: when two integers are divided, the computer assumes the answer must be an integer, also; so, it drops any decimal
how to fix? make the integers double, too
change number1 and number2 from int to double
save; run; now output should say
2.0 divided by 3.0 equals 0.6666666666666666
------------------------------------------------------------------------
BUILD SUCCESS

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!