• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array + Alphabet  RSS feed

 
Donogh Keane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All - can you have a look at the below and let me know what's wrong with the code...

output i get is: "Being: ... thats it noting else

If you can have a look please?



Thanks Donogh
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, you definitely did not give us the full information (ie. only a snippet), as the code that you provided, does not have a main() method that will be called by the JVM. How are you running this code?

Henry
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks like a puzzle or an exam question. 2/3 of the code is meaningless. I suggest a process of elimination.
 
Donogh Keane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Well, you definitely did not give us the full information (ie. only a snippet), as the code that you provided, does not have a main() method that will be called by the JVM. How are you running this code?

Henry


Hi Henry,

Correct - its an assignment in college first yr Java.
Does this not cover the method?: public static void main(String[] args, String[] j, String[] i)

Running code in eclipse....

Thanks,
Donogh
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because you method is named "main" does not mean that the JVM will call it on start up. It has to have the exact correct signature.

Edit: You can have as many methods as you want called "main" with different signatures but only the above signature will be started by the JVM.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and welcome to the Ranch
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you correct your main method's signature, you'll find more problems. The for loop on line 11 will do nothing; the semicolon at the end of that line represents an empty loop body.

The assignment statement on line 12 essentially overwrites what you assigned on line 6; you probably didn't intend for that to happen. I misunderstood the code. This demonstrates why having names like let and let1 in the same block of code is bad practice -- it obscures the code and can mislead the reader. See Carey's comments below for the real problem with the let1 variable.

The braces on lines 9 and 13 are not necessary although they are legal and pose no problems as far as compiling the code is concerned.
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Can you tell us what the requirements are?
 
Donogh Keane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies. The output needs to look as follows:

eg.
char|x|y|Z|Total
b|3|2|4|18

where b is the character the user picked, 3 is the first number the user picked , 2 is the second number the user picked, 4 is the third number the user picked and 18 is the sum of 3, 2 and 4 multiplied by the number equivalent of b (ie. 2)

Thanks for any help

Donogh
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, you might start out very simply by hard coding what you might have entered and then print that out. Come back to implementing user input once you get that working.

What do you mean by "number equivalent of b (ie. 2 )"? How does 'b' become '2'? What if it's a character other than 'b'?
 
Donogh Keane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carey

Thanks for your message. a=1, b=2, c=3, d=4........z=26

Regards

Donogh
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A char is a numeric type. A char of 'a' has a value of 97, and 'z' has a value of 122. How can you take advantage of this knowledge to convert your character to an integer?
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please search this forum because you might find a similar question. This thread from last week also covers a=1, b=2, but I think there might be a more elegant solution than what was found there. My solution only works for the English alphabet and will probably fail horribly for accented letters like é (French) or ü (German). But I haven't told you what my solution is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!