So I am writing code that takes a character and returns its keypad number equivalent. (Think old-school...
$begingroup$
The code I am using is below but I am not getting the character return, only the box with a question-mark.
public char getDigit(char letter) throws Exception{
switch (letter) {
case 'a': case 'b': case 'c': case '2':
return 2;
case 'd': case 'e': case 'f': case '3':
return 3;
case 'g': case 'h': case 'i': case '4':
return 4;
case 'j': case 'k': case 'l': case '5':
return 5;
case 'm': case 'n': case 'o': case '6':
return 6;
case 'p': case 'q': case 'r': case 's': case '7':
return 7;
case 't': case 'u': case 'v': case '8':
return 8;
case 'w': case 'x': case 'y': case 'z': case '9':
return 9;
default:
throw new IllegalArgumentException("Must be a letter or number on the Alpha-Numeric Keypad.");
}
}
I have checked that the input is correct, as an example, the character 'h'. I should get a return of '4'.
Can anyone help me to understand why I am not?
java
New contributor
Justin Hayden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
put on hold as off-topic by Vogel612♦ 39 mins ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
The code I am using is below but I am not getting the character return, only the box with a question-mark.
public char getDigit(char letter) throws Exception{
switch (letter) {
case 'a': case 'b': case 'c': case '2':
return 2;
case 'd': case 'e': case 'f': case '3':
return 3;
case 'g': case 'h': case 'i': case '4':
return 4;
case 'j': case 'k': case 'l': case '5':
return 5;
case 'm': case 'n': case 'o': case '6':
return 6;
case 'p': case 'q': case 'r': case 's': case '7':
return 7;
case 't': case 'u': case 'v': case '8':
return 8;
case 'w': case 'x': case 'y': case 'z': case '9':
return 9;
default:
throw new IllegalArgumentException("Must be a letter or number on the Alpha-Numeric Keypad.");
}
}
I have checked that the input is correct, as an example, the character 'h'. I should get a return of '4'.
Can anyone help me to understand why I am not?
java
New contributor
Justin Hayden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
put on hold as off-topic by Vogel612♦ 39 mins ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
1
$begingroup$
Your question is off-topic and will be closed shortly. We only review working code in an effort to improve it. That said what do you believe you are returning in your switch? anintor achar?
$endgroup$
– bruglesco
2 hours ago
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
39 mins ago
add a comment |
$begingroup$
The code I am using is below but I am not getting the character return, only the box with a question-mark.
public char getDigit(char letter) throws Exception{
switch (letter) {
case 'a': case 'b': case 'c': case '2':
return 2;
case 'd': case 'e': case 'f': case '3':
return 3;
case 'g': case 'h': case 'i': case '4':
return 4;
case 'j': case 'k': case 'l': case '5':
return 5;
case 'm': case 'n': case 'o': case '6':
return 6;
case 'p': case 'q': case 'r': case 's': case '7':
return 7;
case 't': case 'u': case 'v': case '8':
return 8;
case 'w': case 'x': case 'y': case 'z': case '9':
return 9;
default:
throw new IllegalArgumentException("Must be a letter or number on the Alpha-Numeric Keypad.");
}
}
I have checked that the input is correct, as an example, the character 'h'. I should get a return of '4'.
Can anyone help me to understand why I am not?
java
New contributor
Justin Hayden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
The code I am using is below but I am not getting the character return, only the box with a question-mark.
public char getDigit(char letter) throws Exception{
switch (letter) {
case 'a': case 'b': case 'c': case '2':
return 2;
case 'd': case 'e': case 'f': case '3':
return 3;
case 'g': case 'h': case 'i': case '4':
return 4;
case 'j': case 'k': case 'l': case '5':
return 5;
case 'm': case 'n': case 'o': case '6':
return 6;
case 'p': case 'q': case 'r': case 's': case '7':
return 7;
case 't': case 'u': case 'v': case '8':
return 8;
case 'w': case 'x': case 'y': case 'z': case '9':
return 9;
default:
throw new IllegalArgumentException("Must be a letter or number on the Alpha-Numeric Keypad.");
}
}
I have checked that the input is correct, as an example, the character 'h'. I should get a return of '4'.
Can anyone help me to understand why I am not?
java
java
New contributor
Justin Hayden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Justin Hayden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 49 mins ago
bruglesco
1,6562824
1,6562824
New contributor
Justin Hayden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 hours ago
Justin HaydenJustin Hayden
1
1
New contributor
Justin Hayden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Justin Hayden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Justin Hayden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Vogel612♦ 39 mins ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by Vogel612♦ 39 mins ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
1
$begingroup$
Your question is off-topic and will be closed shortly. We only review working code in an effort to improve it. That said what do you believe you are returning in your switch? anintor achar?
$endgroup$
– bruglesco
2 hours ago
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
39 mins ago
add a comment |
1
$begingroup$
Your question is off-topic and will be closed shortly. We only review working code in an effort to improve it. That said what do you believe you are returning in your switch? anintor achar?
$endgroup$
– bruglesco
2 hours ago
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
39 mins ago
1
1
$begingroup$
Your question is off-topic and will be closed shortly. We only review working code in an effort to improve it. That said what do you believe you are returning in your switch? an
int or a char?$endgroup$
– bruglesco
2 hours ago
$begingroup$
Your question is off-topic and will be closed shortly. We only review working code in an effort to improve it. That said what do you believe you are returning in your switch? an
int or a char?$endgroup$
– bruglesco
2 hours ago
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
39 mins ago
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
39 mins ago
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
$begingroup$
Your question is off-topic and will be closed shortly. We only review working code in an effort to improve it. That said what do you believe you are returning in your switch? an
intor achar?$endgroup$
– bruglesco
2 hours ago
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
39 mins ago