• Post Reply 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Question relating to arrays

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ch is an array not a single character
 
Justice Smith
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 539
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
x is getting initialised to 0 every time inside the for loop.
 
lowercase baba
Posts: 12992
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12992
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Marshal
Posts: 73266
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 73266
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use number literals in for loops. Use myArray.length.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic