Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

here) and other areas you consider relevant.

Answered: 1 week ago