A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Opcode

  • one year ago

Write a program in Java that converts meters, to feet without using any types of loops. What is did was create to methods, one for converting feet to meters, the other converting meters to feet. Then I used the incremental operator, and then printed out the variable each time. However the program did not format the variables to my liking how do I fix this?

  • This Question is Closed
  1. Opcode
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I should mention I cannot use DecimalFormat, and the instructor want me to use something of "%4.3f" whatever that is.

  2. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    You shouldn't need loops for converting units. All you need is numbers and multiplication. When your instructor is talking about %4.3f, they are talking about representing the decimal in a string. This is called string formatting. Here's a page from the documentation on it: https://docs.oracle.com/javase/tutorial/java/data/numberformat.html. You should definitely read through it. Let's say you wanted to represent a float variable in a string, you would do the following. float pi = 3.1415927f; String output = String.format("Pi: %f", pi); Now let's say you wanted to set the precision to 3, you would do: String output = String.format("Pi: %.3f", pi); Everything else you need to know about formatting in Java is in that documentation. But here's a working solution for your problem: https://gist.github.com/AlexeyNosych/cb2fbd38d320219a8b47

  3. Opcode
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Exactly what I was looking for, thank you.

  4. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.