Question

Floats.java Use the following calculations for di and d2 in your code: double di = 0; // add .1 to 0 eleven times d1 += 1; //

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Floats
{
   public static void main(String args[])
   {
       double d1 = 0;
       //add 0.1 for 11 times to d1
       d1 += 0.1;
       d1 += 0.1;
       d1 += 0.1;
       d1 += 0.1;
       d1 += 0.1;
       d1 += 0.1;
       d1 += 0.1;
       d1 += 0.1;
       d1 += 0.1;
       d1 += 0.1;
       d1 += 0.1;
       //multiply 0.1 with 11
       double d2 = 0.1 * 11;
       //round d1 to 1 decimal place
       double rounded = Math.round(d1 * 10)/10.0;
       //compare the rounded value with d2
       if(rounded == d2)
       {
           //if they are equal print it
           System.out.println(d1 + " is equal to " + d2);
       }
       else
       {
           //if they are not equal print it
           System.out.println(d1 + " is not equal to " + d2);
       }
   }
}

Activities Terminal Sun 10:41 deepika@deepika-TravelMate-P243-M: -/Desktop File Edit View Search Terminal Help deepika@deepik

If you have any doubts please comment and please don't dislike.

Add a comment
Know the answer?
Add Answer to:
Floats.java Use the following calculations for di and d2 in your code: double di = 0;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • share your program enhance your work after submitting export to repl Due: Oct 12, 2020 05:00...

    share your program enhance your work after submitting export to repl Due: Oct 12, 2020 05:00 pm submit : back to classroom run Instructions from your teacher: #include <iostream> Complete this program. using namespace std; When the program is complete it should ask the user to enter a rectangle's length and width, then display the rectangle's area. The program calls the following functions which need to be completed: double getLength() { // Add code here } double getWidth() { //...

  • Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You...

    Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You can initialize the variables to any legal value of your choosing. Next, declare and initialize a pointer variable to each of the variables Using printf), output the following: The address of each of the first three variables. Use the "Ox%x" format specifier to print the addresses in hexadecimal notation The value of each variable. They should equal the value you gave...

  • In c++ #include <iostream > 2 #include <set> #înclude <functional» 5 using namespace std; 7 //your...

    In c++ #include <iostream > 2 #include <set> #înclude <functional» 5 using namespace std; 7 //your code 9 int main) 4 6 8 1e set <double, greater<double>>valuesA --1.1, 2.9, -2.3, 2.71 J: set <double, greater<double>> valuesB -3.14, 2.71, -3.88, 2.19; double value; cin > value; 12 13 14 15 16 17 18 19 /your code return ; Scenario Write a program that creates two sets (the sets are given in the code below) and asks the user for a number....

  • This is my code so far for the assignment. I am stuck on the last 3...

    This is my code so far for the assignment. I am stuck on the last 3 tasks which are task#3, task#4 and task#5. Task #3 String Comparisons In checkForDiscount() method of the driver: 1. Figure out if there is a discount of $2 on this order, due to the customer's name being either Mike or Diane 2. Return either 2 or 0 as the discount to the cost of the pizza 3. Compile, debug, and run. You should now be...

  • C++ programming language , I need help writing the code . Please explain if you can...

    C++ programming language , I need help writing the code . Please explain if you can . Exercise 10: Unit conversion (10 points) Write a console program that converts meters into feet and inches. The program starts by asking the user for a measurement in meters. The program should accept a floating point number. After getting the number, the program computes the number of feet and inches equal to the specified number of meters. The program outputs feet and inches...

  • Please code this in java: The purpose of this assignment is to: Read double data in...

    Please code this in java: The purpose of this assignment is to: Read double data in to a TreeSet where each datum inserted is Math.abs(datum) (i.e., no negative values are inserted). NOTE: This will (i) sort the data placed into the TreeSet, and, (ii) remove duplicate values since no duplicates are allowed (i.e., duplicates will not be inserted). Create a list iterator. Iterate backwards through the TreeSet (i.e., from the largest value to the smallest) outputting all elements * -1.0....

  • Please solve using Java and comment your code for clarity. Sample 3. Input: 4 1 231...

    Please solve using Java and comment your code for clarity. Sample 3. Input: 4 1 231 Output: 0 This sequence also does not have a majority element (note that the element 1 appears twice and hence is not a majority element). Problem Introduction Majority rule is a decision rule that selects the alternative which has a majority, that is, more than half the votes. Given a sequence of elements (1.02....,On, you would like to check whether it contains an element...

  • Question 1 The code used to output messages to the screen begins with run # print...

    Question 1 The code used to output messages to the screen begins with run # print output Flag this Question Question 2 The code used to begin a comment in the Python program source code is # Hello * Comment Flag this Question Question 3 A variable name is like a(n) input typed on a keyboard address in computer memory where values can be stored output to a computer screen value assigned to an address in computer memory Flag this...

  • c++ Note: Do not use using namespace std; Use std:: Use comments for clear understanding TEST...

    c++ Note: Do not use using namespace std; Use std:: Use comments for clear understanding TEST THE PROGRAM. 1) Create a c++ program to run a simple experiment to see how reference parameters work. 2) You need to add a “&” symbol after the parameter type specification to set up a reference parameter: int myfunc (int & x) { x = 11; return -11; } int testdata = 0; int y; y= myfunc (testdata); 3) Now, You can get a...

  • Do not use pointer variables, pointer arithmetic or operater new ITCS-2530    Project                        Write an...

    Do not use pointer variables, pointer arithmetic or operater new ITCS-2530    Project                        Write an interactive program that performs fractional calculations. You need define a class CFrac for a fractional number according to the UML diagram below: CFrac - numerator : int - denominator : int - simplify () : void + CFrac (int = 0, int = 1) + ~CFrac() + add (const CFrac&) const : CFrac + subtract (const CFrac&) const : CFrac + multiply (const CFrac&)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT