r/programminghelp • • Nov 17 '19

Taxes.java:21 error: illegal start of expression ....... How is that an illegal start of the expression!!!! Just started working with multiple methods and I'm don't understand what I'm doing wrong πŸ˜” help pwease πŸ’œ

Post image
4 Upvotes

18 comments sorted by

4

u/BlueBlus Nov 17 '19

You have a function within a function. Close the main.

1

u/Liberty_53000 Nov 17 '19

Bah thank youuu so much!! Those squigly's will be my downfall one day πŸ˜…

1

u/3xcelzior Nov 17 '19

Welcome to the horrors of debugging. It’s a journey you will hate more and more the longer your code gets. Enjoy lol

1

u/Liberty_53000 Nov 17 '19

Haha yea always the best part sarcasm LOL now got it to run... But there's a problem with the output πŸ˜…

1

u/3xcelzior Nov 17 '19

What’s the problem? More of a c and python guy but I’ll help if I can. Took a class on java in middle school about 10 years ago so I’m kinda rusty tbh lol

1

u/Liberty_53000 Nov 17 '19

Well it's supposed to round to the hundredths place and it's rounding all the way Ex, I put in 23451 and expect it to output that I owe $3517.65 instead I'm getting an output of $3517.0

1

u/3xcelzior Nov 17 '19

Math.round(taxes * 100) / 100

That should do the trick. Gotta fool the system by rounding to a whole number and then bringing the decimals back

2

u/Liberty_53000 Nov 17 '19

It didn't work at first but I changed all the 100 to 100.00 πŸ™ŒπŸ™ŒπŸ™Œ thank you soooooo muchhh for your help!!!!

1

u/3xcelzior Nov 17 '19

Ah shit. I forgot java is weird with writing your numbers as what they are when initializing. Aka double = 0.0, int = 0

Each language has such weird quirks lol

1

u/3xcelzior Nov 17 '19

This will work too

Import java.text.DecimalFormat; DecimalFormat format = new DecimalFormat(β€œ##.00”); Math.round(format.format(taxes));

1

u/Liberty_53000 Nov 17 '19

In middle school shesh I wish they offered that at my school, taking my first intro to Java in college. Did some python on my own with code academy years ago, now wishing I did Java back then. πŸ˜…

2

u/3xcelzior Nov 17 '19

Ya it was basic stuff but I was the first class to get it. My mom is a school teacher and mentioned it to the IT guys that I wanted to learn programming. One of the guys offered to teach a class and the school approved.

1

u/Liberty_53000 Nov 17 '19

That's awesome! I feel like it really should be offered to all schools starting in middle school as a great place to start. My older brother helped me learn it/ set me up with code academy / gave me hw ex. cause it wasn't offered.

1

u/3xcelzior Nov 17 '19

Ya it’s a really good skill to have in your toolbox. Makes you really marketable. I graduate this year and know a decent amount of languages and I’m pretty confident with learning new languages and concepts at this point.
If you wanna get really good with coding and debugging try and make your own arch Linux setup with i3 or awesome wm and customize it all yourself. It’s fun and challenging. Makes you explore different languages and concepts. Plus it helps teach you a lot about how computer file systems work. And using bash/Linux will be really helpful later on.

1

u/Liberty_53000 Nov 17 '19

Thank you I will definitely look into that! Always looking for new ways to challenge myself especially with coding, I'm a computer science major and plan on looking for a job specifically coding so I need all the knowledge I can get about it!! Plus iz fun... Sometimes xD

→ More replies (0)

1

u/bluebird173 Nov 18 '19

why would you ever post a picture of your code??? just copy and paste it! you're on desktop! what!?

1

u/Liberty_53000 Nov 18 '19 edited Nov 18 '19

Because Ive never logged into redit on my computer... What's it matter any ways? It's a school assignment in an intro to programming class I don't think it matters.