#Floating-point numbers (double) ((basic java))
1 messages · Page 1 of 1 (latest)
Oh it's just a string formatting issue
You made a mistake. It should be %.2f and %.4f you wrote %.2 and %.4. you just forgot to put the f which indicates what type your are printing.
does printf only read the first bit?
There's another thing
like scnr.next() does?
You don't put the variables in the formating
Here's an example
double x = 12.1545268184;
System.out.printf("x = %.2f", x);
hmm so what would my line look like?
x = 12.15
You can figure it out from what I've sent
its all one line right?
Another note, you don't need to do the concatenation in your printf.
does that just mean the + or does that include the " " as well?
im really hoping i look back on this in a few months and think its funny
What I means by that it's that you can write the string as one and don't need to add multiple strings together
im tapped
my output is just q =
serious head scratcher
i wont bother u anymore tho i appreciate it
Don't abandon
Your almost there
And you are not bothering me. I if didn't want to answer I wouldn't
well that makes me feel better
okay
so heres where im at
System.out.printf("q = %.4f when u = %.2f");
I'll reiterate on the issues
- You forgot the format type which in your case is f. So
%.2should be%.2f - You need to pass values to the printf method
- you don't need to concatenate the strings
so do i do them in sperate lines?
With that you solved 2 of the 3 issues I just sent you. Can you tell me which one is missing
Look at my example of earlier. Can you see what I did to replace %.2f by the value of x
;compile
double x = 12.1545268184;
System.out.printf("x = %.2f", x);
x = 12.15
you assigned x the value
and then uhh
honestly feel like itd be easier to know what the line should be
so i can try and conceptualize why that is
i dont get why the complier stops at the whitespace after the =
You'll see it once you get it. I could show you but trust me it won't help you that I just show you. Right now I'm making your brain work and trying to understand what's going on. It sucks on the moment but it's going to be much better for understanding.
You're not passing the values to the method
Look at my example
What comes after the string
So what printf does is it takes a string and a bunch of values and replace the format specifier (ex. %f) by the values your are providing to the method
so far i just checked it as
System.out.printf("q = %.4f ", q);
and that got me the output "q = -10.0000
now to add the "when u = 1.00"
does that get added to a separate line?
No
The string you had before is already good. Printf can have multiple values given to it
is there a special formatting for after the ,q?
like do i use a + for the second bit
or can it squeeze in there
What do you mean by squeeze it in there?
i tried..
System.out.printf("q %.4f ", q "when u = %.2f ", u);
but naturally
that did not work
System.out.printf("q = %.4f when u = %.2f"); this line is already good. The only missing things are the values which are q and u. You figured out how to do it for q. It would give this System.out.printf("q = %.4f when u = %.2f", q);.
Now if I'd tell you that you need to add another value how would you do it. (don't change the string)
i cant just comma u i assume
Have you read this
So what printf does is it takes a string and a bunch of values and replace the format specifier (ex.
%f) by the values your are providing to the method
mfw now i need a new line
but this is wild
maybe i shouldve taken this one in person 💀
Well you just add \n at the end of the string
What do you mean?
figured programming 1 couldn't be too bad
Btw, here's the documentation about printf and format syntax
https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax
so i kept my work availability open
buyers remorse settling for that one
why is it saying that \n is illegal?
Can I see how you wrote it?
It needs to be in the string
Here we go
Hahaha no don't worry. I'm used to that
the professor said the beginning would be rough
pretty foreign concept at the start of it all
biology, chemistry, history, art... most people have an idea or 2 of what they're about
They are right. It can take time before things clicks. The secret is lots of practice.
programming is usually extremely out there at the beginning
cause at no point are you really exposed to the ideas
man was right lol
thats why im here
i submitted this for a C
but im going back and practicing because i want to learn
and dont want to fall behind on concepts
That's the smart thing to do
Can you re-submit it? Late can be (depending on how much time and also the teacher) better than incomplete
Oh well, you'll have to do better on the next assignment.
yup
i worked until 6pm did not expect this unit to be so tedious
only the 2nd one
first one was a lot easier
print, scnr, some math
println was the craziest thing that happened in that one
Yea next time you'll be able to judge better the time and effort it requires and also ask questions before it's too late
I see
100%
im off work for the next few days gonna get on the upcoming one tmrw
hence me going back on this one
feel like starting that one without knowing all of this one is gonna be extra difficult
Yea it totally make sense. It was a good idea to finish that one first