File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes why does it tell me that there is else without if (java programming)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

why does it tell me that there is else without if (java programming)?

Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

I get this output

The numbers shown, are the decimal number of hex value like in the first link, and code you posted.

Regards, Rene Larsen
Dropbox Invite
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

But if you change the for loop like this

you'll get the char values
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

Dmitri Makovetskiy wrote:

i want to convert all those while loops to for. this would allow me to use if and else.

You can use if-else statements with while loops, too.

Dmitri Makovetskiy wrote:
i must have if and else's.

Why? If you're thinking goes "I MUST use THIS data structure" or "I MUST use THAT control structure", you're not approaching the problem right. You're saying "I HAVE to use a hammer, even thought I want to drill a hole". You should be saying "I need to drill a hole, so the best tool would be a drill".

Dmitri Makovetskiy wrote:
The structure should be like that.
the letter appears in the string
print it

if it doesnt
ask for another number.

Are you saying you want to verify the user input, character by character?

Dmitri Makovetskiy wrote:
so far the code isnt working and tells me there is a mistake
I"m not surprised. You seem to be simply firing random chunks of code at us, saying "This doesn't work". You need to stop and back up. What EXACTLY are you trying to do? I think you want to do this:

Ask the user to input a hex. number
While the number is not valid hex, ask them to try again
once they have input a valid hex number, print the decimal equivalent.

Is that correct?

Dmitri Makovetskiy wrote:to tell you the truth. i dont think my code will recognize 2000 as a value... i think i need to redesign the whole thing, with different loops. what do you think?

I honestly can't even look at your code anymore, because it's not clear what you're trying to do. The best way to approach this is to write out step by step what should happen. Keep refining it until it's crystal clear to everyone what should occur. then start coding it in as little pieces as possible, and testing it as often as possible. Only when you're sure what you just wrote works flawlessly should you try and do the next step.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Steve Fahlbusch

Joined: Sep 18, 2000
Posts: 602

Guys, (talking to the folks that have been attempting to get the OP to do the right thing)

This post is also cross-posted. crosspost. This OP knows our (ie: this site's) rules, has been notified to inform of such, and has even been barred from other sites because of this.

Now i don't want to be considered to be not nice, but i dont want any of you to be wasting your time.


To the OP.

You might want to actually study what you are supposed to be studying - you are taking a course and you should be doing the background work - ie: read the book, understand the requirements, create a full test suite, design your approach, work it through (ie: paper and pencil) write it, test it. Then if you have issues, post your requirements, your attempt and your test results.

And please, please take time to actually read the posts of others and do the effort.

I agree. Here's the link:
subject: why does it tell me that there is else without if (java programming)?
It's not a secret anymore!