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?
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
I should mention I cannot use DecimalFormat, and the instructor want me to use something of "%4.3f" whatever that is.
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