Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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

Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
  • Report post to moderator
I get this output

The numbers shown, are the decimal number of hex value like in the first link, and code you posted.
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
  • Report post to moderator
But if you change the for loop like this

you'll get the char values
lowercase baba
Posts: 12751
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator

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.
Posts: 612
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.

    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!