Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question relating to arrays  RSS feed

 
Justice Smith
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know there are probably multiple problems with this code, but I'm specifically at a loss as to why it tells me "incompatible types" on line 11. Any help would be great.

 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ch is an array not a single character
 
Justice Smith
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. So, I fixed that problem, but the output is not what I would like. It is supposed to output the alphabet, separated by a comma and space. What it a actually outputs is "Z, , , ," and on through 26 total commas and spaces. How do I fix this?

 
Prasanna Raman
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
x is getting initialised to 0 every time inside the for loop.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest you StopCoding and read that FAQ.

programming is roughly 80% thinking/planning, and only 20% writing code. You need to be able to write out step by step what is going to happen. Your instructions should be simple enough that a 10-yr old child can follow them.

Once you have done that...THEN you start writing code.
 
Justice Smith
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, what a silly mistake. Fred, I appreciate the advice, but I'm just trying to learn for fun, and I've always learned the most by trial and error. I'm sure it's not the most efficient way to learn Java, but it's always worked well for me.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are just screwing around, then by all means, try something, see what happens, try something else. As long as you realize you'll probably never write anything very complex this way, and you're OK with that, the have fun!!!
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using 65 and 90? If chars are numbers, why not use the letter value?
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use number literals in for loops. Use myArray.length.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!