Taking int input and parsing into char

Multi tool use
up vote
1
down vote
favorite
So my main got deleted 2 days ago and my teacher helped me a bit with the switch
code. I rebuilt the code yesterday and he was away yesterday and could not help me.
public static void main(String args) throws InterruptedException
do
try
System.out.println("Enter your birthYear");
birthYear = Integer.parseInt(input.next());
int length = String.valueOf(birthYear).length();
System.out.println(length);
if (length != 4)
lengthTest = false;
System.out.println("Invalid Choice");
else
lengthTest = true;
test = true;
catch (Exception e)
System.out.println("Invalid Choice");
while (test == true ^ lengthTest != false);
do
System.out.println("Please enter a number between 1-4 n"
+ "1 = AreaOfTriangle n" +
"----------------------------------n" +
"2 = HoursToDaysAndHours Calculator n" +
"---------------------------------- n" +
"3 = CelciusToFahrenheit Calculator n" +
"----------------------------------n" +
"4 = BirthdayGame rn" +
"----------------------------------");
try
choice = Integer.toString(input.nextInt()).charAt(0);
System.out.println(choice);
switch (choice)
case 1:
aOT.areaOfTriangle();
break;
case 2:
hTDAH.hoursToDaysAndHours();
break;
case 3:
cTF.celciusToFahrenheit();
case 4:
System.out.println("Code not implemented");
break;
case 'e':
repeat = false;
break;
default:
System.out.println("");
break;
catch (Exception e)
System.out.println("Invalid Awnser");
while (repeat == true);
My problem is in my switch case i want to be able to use int's and Char's at the same time. For example i want to use e to exit and and the 4 numbers
java string char int
add a comment |
up vote
1
down vote
favorite
So my main got deleted 2 days ago and my teacher helped me a bit with the switch
code. I rebuilt the code yesterday and he was away yesterday and could not help me.
public static void main(String args) throws InterruptedException
do
try
System.out.println("Enter your birthYear");
birthYear = Integer.parseInt(input.next());
int length = String.valueOf(birthYear).length();
System.out.println(length);
if (length != 4)
lengthTest = false;
System.out.println("Invalid Choice");
else
lengthTest = true;
test = true;
catch (Exception e)
System.out.println("Invalid Choice");
while (test == true ^ lengthTest != false);
do
System.out.println("Please enter a number between 1-4 n"
+ "1 = AreaOfTriangle n" +
"----------------------------------n" +
"2 = HoursToDaysAndHours Calculator n" +
"---------------------------------- n" +
"3 = CelciusToFahrenheit Calculator n" +
"----------------------------------n" +
"4 = BirthdayGame rn" +
"----------------------------------");
try
choice = Integer.toString(input.nextInt()).charAt(0);
System.out.println(choice);
switch (choice)
case 1:
aOT.areaOfTriangle();
break;
case 2:
hTDAH.hoursToDaysAndHours();
break;
case 3:
cTF.celciusToFahrenheit();
case 4:
System.out.println("Code not implemented");
break;
case 'e':
repeat = false;
break;
default:
System.out.println("");
break;
catch (Exception e)
System.out.println("Invalid Awnser");
while (repeat == true);
My problem is in my switch case i want to be able to use int's and Char's at the same time. For example i want to use e to exit and and the 4 numbers
java string char int
3
And your question is?
– GBlodgett
Nov 10 at 19:52
1
while (repeat == true)
is the same aswhile (repeat)
andwhile (test == true ^ lengthTest != false)
is the same aswhile (test != !lengthTest)
which seems wrong or overly complicated.
– Peter Lawrey
Nov 10 at 19:55
I would replacechoice = Integer.toString(input.nextInt()).charAt(0)
withchoice = input.nextInt()
– Peter Lawrey
Nov 10 at 19:55
I would also print any exception as it might be important as to which one.
– Peter Lawrey
Nov 10 at 19:56
@PeterLawrey yes you are correct. I made much more simple by removingtest
and now I am just doingwhile (!lengthTest);
– Nuggethed2003
Nov 11 at 0:45
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
So my main got deleted 2 days ago and my teacher helped me a bit with the switch
code. I rebuilt the code yesterday and he was away yesterday and could not help me.
public static void main(String args) throws InterruptedException
do
try
System.out.println("Enter your birthYear");
birthYear = Integer.parseInt(input.next());
int length = String.valueOf(birthYear).length();
System.out.println(length);
if (length != 4)
lengthTest = false;
System.out.println("Invalid Choice");
else
lengthTest = true;
test = true;
catch (Exception e)
System.out.println("Invalid Choice");
while (test == true ^ lengthTest != false);
do
System.out.println("Please enter a number between 1-4 n"
+ "1 = AreaOfTriangle n" +
"----------------------------------n" +
"2 = HoursToDaysAndHours Calculator n" +
"---------------------------------- n" +
"3 = CelciusToFahrenheit Calculator n" +
"----------------------------------n" +
"4 = BirthdayGame rn" +
"----------------------------------");
try
choice = Integer.toString(input.nextInt()).charAt(0);
System.out.println(choice);
switch (choice)
case 1:
aOT.areaOfTriangle();
break;
case 2:
hTDAH.hoursToDaysAndHours();
break;
case 3:
cTF.celciusToFahrenheit();
case 4:
System.out.println("Code not implemented");
break;
case 'e':
repeat = false;
break;
default:
System.out.println("");
break;
catch (Exception e)
System.out.println("Invalid Awnser");
while (repeat == true);
My problem is in my switch case i want to be able to use int's and Char's at the same time. For example i want to use e to exit and and the 4 numbers
java string char int
So my main got deleted 2 days ago and my teacher helped me a bit with the switch
code. I rebuilt the code yesterday and he was away yesterday and could not help me.
public static void main(String args) throws InterruptedException
do
try
System.out.println("Enter your birthYear");
birthYear = Integer.parseInt(input.next());
int length = String.valueOf(birthYear).length();
System.out.println(length);
if (length != 4)
lengthTest = false;
System.out.println("Invalid Choice");
else
lengthTest = true;
test = true;
catch (Exception e)
System.out.println("Invalid Choice");
while (test == true ^ lengthTest != false);
do
System.out.println("Please enter a number between 1-4 n"
+ "1 = AreaOfTriangle n" +
"----------------------------------n" +
"2 = HoursToDaysAndHours Calculator n" +
"---------------------------------- n" +
"3 = CelciusToFahrenheit Calculator n" +
"----------------------------------n" +
"4 = BirthdayGame rn" +
"----------------------------------");
try
choice = Integer.toString(input.nextInt()).charAt(0);
System.out.println(choice);
switch (choice)
case 1:
aOT.areaOfTriangle();
break;
case 2:
hTDAH.hoursToDaysAndHours();
break;
case 3:
cTF.celciusToFahrenheit();
case 4:
System.out.println("Code not implemented");
break;
case 'e':
repeat = false;
break;
default:
System.out.println("");
break;
catch (Exception e)
System.out.println("Invalid Awnser");
while (repeat == true);
My problem is in my switch case i want to be able to use int's and Char's at the same time. For example i want to use e to exit and and the 4 numbers
java string char int
java string char int
edited Nov 10 at 19:56
asked Nov 10 at 19:52


Nuggethed2003
84
84
3
And your question is?
– GBlodgett
Nov 10 at 19:52
1
while (repeat == true)
is the same aswhile (repeat)
andwhile (test == true ^ lengthTest != false)
is the same aswhile (test != !lengthTest)
which seems wrong or overly complicated.
– Peter Lawrey
Nov 10 at 19:55
I would replacechoice = Integer.toString(input.nextInt()).charAt(0)
withchoice = input.nextInt()
– Peter Lawrey
Nov 10 at 19:55
I would also print any exception as it might be important as to which one.
– Peter Lawrey
Nov 10 at 19:56
@PeterLawrey yes you are correct. I made much more simple by removingtest
and now I am just doingwhile (!lengthTest);
– Nuggethed2003
Nov 11 at 0:45
add a comment |
3
And your question is?
– GBlodgett
Nov 10 at 19:52
1
while (repeat == true)
is the same aswhile (repeat)
andwhile (test == true ^ lengthTest != false)
is the same aswhile (test != !lengthTest)
which seems wrong or overly complicated.
– Peter Lawrey
Nov 10 at 19:55
I would replacechoice = Integer.toString(input.nextInt()).charAt(0)
withchoice = input.nextInt()
– Peter Lawrey
Nov 10 at 19:55
I would also print any exception as it might be important as to which one.
– Peter Lawrey
Nov 10 at 19:56
@PeterLawrey yes you are correct. I made much more simple by removingtest
and now I am just doingwhile (!lengthTest);
– Nuggethed2003
Nov 11 at 0:45
3
3
And your question is?
– GBlodgett
Nov 10 at 19:52
And your question is?
– GBlodgett
Nov 10 at 19:52
1
1
while (repeat == true)
is the same as while (repeat)
and while (test == true ^ lengthTest != false)
is the same as while (test != !lengthTest)
which seems wrong or overly complicated.– Peter Lawrey
Nov 10 at 19:55
while (repeat == true)
is the same as while (repeat)
and while (test == true ^ lengthTest != false)
is the same as while (test != !lengthTest)
which seems wrong or overly complicated.– Peter Lawrey
Nov 10 at 19:55
I would replace
choice = Integer.toString(input.nextInt()).charAt(0)
with choice = input.nextInt()
– Peter Lawrey
Nov 10 at 19:55
I would replace
choice = Integer.toString(input.nextInt()).charAt(0)
with choice = input.nextInt()
– Peter Lawrey
Nov 10 at 19:55
I would also print any exception as it might be important as to which one.
– Peter Lawrey
Nov 10 at 19:56
I would also print any exception as it might be important as to which one.
– Peter Lawrey
Nov 10 at 19:56
@PeterLawrey yes you are correct. I made much more simple by removing
test
and now I am just doing while (!lengthTest);
– Nuggethed2003
Nov 11 at 0:45
@PeterLawrey yes you are correct. I made much more simple by removing
test
and now I am just doing while (!lengthTest);
– Nuggethed2003
Nov 11 at 0:45
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
accepted
You can try to use String as an input paramenter, then any int value or char will be readed correctly without necessity to convert them:
try {
String choice = input.next();
System.out.println(choice);
switch (choice)
case "1":
aOT.areaOfTriangle();
break;
case "2":
hTDAH.hoursToDaysAndHours();
break;
case "3":
cTF.celciusToFahrenheit();
case "4":
System.out.println("Code not implemented");
break;
case "e":
repeat = false;
break;
default:
System.out.println("");
break;
That did the trick! I also added.toLowerCase();
to ignore Uppercase or Lower case
– Nuggethed2003
Nov 11 at 0:49
add a comment |
up vote
0
down vote
You can't use int and chars at the same time, as you can only use one variable and a variable has to have a type, but:
If you cast a char or Character to int you get values. For example ((int) 'e') evaluates to 101 if I am not mistaken. (Try System.out.println((int) 'e'));
So in your case, you can switch over int values and detect for 1,2,3,4 and 101.
Your default should also throw an exception and you are fine.
Happy Coding
Lets say the user inputs 101 in the input, will that exit the code?
– Nuggethed2003
Nov 10 at 20:39
yes, then you have a problem :-) That's why in a real project you should do input checking an probably convert from types some semantic enum.
– user10419911
Nov 10 at 22:22
Yes I got it if fixed from the solution above. Changed it to String and it works
– Nuggethed2003
Nov 11 at 0:47
Yeah, that's the best solution here :)
– user10419911
Nov 11 at 16:27
add a comment |
up vote
0
down vote
You could just use the char
representations of the digits 1-4:
char choice = input.next().charAt(0);
switch (choice)
case '1':
aOT.areaOfTriangle();
break;
case '2':
hTDAH.hoursToDaysAndHours();
break;
case '3':
cTF.celciusToFahrenheit();
case '4':
System.out.println("Code not implemented");
break;
case 'e':
repeat = false;
break;
default:
System.out.println("");
break;
Thechar choice = input.nextInt().charAt(0);
didnt work it gave meCannot invoke charAt(int) on the primitive type int
– Nuggethed2003
Nov 10 at 20:40
@Nuggethed2003 meant to usenext()
, notnextInt()
, sorry. Edited and fixed.
– Mureinik
Nov 11 at 2:43
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242827%2ftaking-int-input-and-parsing-into-char%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can try to use String as an input paramenter, then any int value or char will be readed correctly without necessity to convert them:
try {
String choice = input.next();
System.out.println(choice);
switch (choice)
case "1":
aOT.areaOfTriangle();
break;
case "2":
hTDAH.hoursToDaysAndHours();
break;
case "3":
cTF.celciusToFahrenheit();
case "4":
System.out.println("Code not implemented");
break;
case "e":
repeat = false;
break;
default:
System.out.println("");
break;
That did the trick! I also added.toLowerCase();
to ignore Uppercase or Lower case
– Nuggethed2003
Nov 11 at 0:49
add a comment |
up vote
0
down vote
accepted
You can try to use String as an input paramenter, then any int value or char will be readed correctly without necessity to convert them:
try {
String choice = input.next();
System.out.println(choice);
switch (choice)
case "1":
aOT.areaOfTriangle();
break;
case "2":
hTDAH.hoursToDaysAndHours();
break;
case "3":
cTF.celciusToFahrenheit();
case "4":
System.out.println("Code not implemented");
break;
case "e":
repeat = false;
break;
default:
System.out.println("");
break;
That did the trick! I also added.toLowerCase();
to ignore Uppercase or Lower case
– Nuggethed2003
Nov 11 at 0:49
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can try to use String as an input paramenter, then any int value or char will be readed correctly without necessity to convert them:
try {
String choice = input.next();
System.out.println(choice);
switch (choice)
case "1":
aOT.areaOfTriangle();
break;
case "2":
hTDAH.hoursToDaysAndHours();
break;
case "3":
cTF.celciusToFahrenheit();
case "4":
System.out.println("Code not implemented");
break;
case "e":
repeat = false;
break;
default:
System.out.println("");
break;
You can try to use String as an input paramenter, then any int value or char will be readed correctly without necessity to convert them:
try {
String choice = input.next();
System.out.println(choice);
switch (choice)
case "1":
aOT.areaOfTriangle();
break;
case "2":
hTDAH.hoursToDaysAndHours();
break;
case "3":
cTF.celciusToFahrenheit();
case "4":
System.out.println("Code not implemented");
break;
case "e":
repeat = false;
break;
default:
System.out.println("");
break;
answered Nov 10 at 21:42


Sergei Voychuk
635
635
That did the trick! I also added.toLowerCase();
to ignore Uppercase or Lower case
– Nuggethed2003
Nov 11 at 0:49
add a comment |
That did the trick! I also added.toLowerCase();
to ignore Uppercase or Lower case
– Nuggethed2003
Nov 11 at 0:49
That did the trick! I also added
.toLowerCase();
to ignore Uppercase or Lower case– Nuggethed2003
Nov 11 at 0:49
That did the trick! I also added
.toLowerCase();
to ignore Uppercase or Lower case– Nuggethed2003
Nov 11 at 0:49
add a comment |
up vote
0
down vote
You can't use int and chars at the same time, as you can only use one variable and a variable has to have a type, but:
If you cast a char or Character to int you get values. For example ((int) 'e') evaluates to 101 if I am not mistaken. (Try System.out.println((int) 'e'));
So in your case, you can switch over int values and detect for 1,2,3,4 and 101.
Your default should also throw an exception and you are fine.
Happy Coding
Lets say the user inputs 101 in the input, will that exit the code?
– Nuggethed2003
Nov 10 at 20:39
yes, then you have a problem :-) That's why in a real project you should do input checking an probably convert from types some semantic enum.
– user10419911
Nov 10 at 22:22
Yes I got it if fixed from the solution above. Changed it to String and it works
– Nuggethed2003
Nov 11 at 0:47
Yeah, that's the best solution here :)
– user10419911
Nov 11 at 16:27
add a comment |
up vote
0
down vote
You can't use int and chars at the same time, as you can only use one variable and a variable has to have a type, but:
If you cast a char or Character to int you get values. For example ((int) 'e') evaluates to 101 if I am not mistaken. (Try System.out.println((int) 'e'));
So in your case, you can switch over int values and detect for 1,2,3,4 and 101.
Your default should also throw an exception and you are fine.
Happy Coding
Lets say the user inputs 101 in the input, will that exit the code?
– Nuggethed2003
Nov 10 at 20:39
yes, then you have a problem :-) That's why in a real project you should do input checking an probably convert from types some semantic enum.
– user10419911
Nov 10 at 22:22
Yes I got it if fixed from the solution above. Changed it to String and it works
– Nuggethed2003
Nov 11 at 0:47
Yeah, that's the best solution here :)
– user10419911
Nov 11 at 16:27
add a comment |
up vote
0
down vote
up vote
0
down vote
You can't use int and chars at the same time, as you can only use one variable and a variable has to have a type, but:
If you cast a char or Character to int you get values. For example ((int) 'e') evaluates to 101 if I am not mistaken. (Try System.out.println((int) 'e'));
So in your case, you can switch over int values and detect for 1,2,3,4 and 101.
Your default should also throw an exception and you are fine.
Happy Coding
You can't use int and chars at the same time, as you can only use one variable and a variable has to have a type, but:
If you cast a char or Character to int you get values. For example ((int) 'e') evaluates to 101 if I am not mistaken. (Try System.out.println((int) 'e'));
So in your case, you can switch over int values and detect for 1,2,3,4 and 101.
Your default should also throw an exception and you are fine.
Happy Coding
answered Nov 10 at 20:07
user10419911
Lets say the user inputs 101 in the input, will that exit the code?
– Nuggethed2003
Nov 10 at 20:39
yes, then you have a problem :-) That's why in a real project you should do input checking an probably convert from types some semantic enum.
– user10419911
Nov 10 at 22:22
Yes I got it if fixed from the solution above. Changed it to String and it works
– Nuggethed2003
Nov 11 at 0:47
Yeah, that's the best solution here :)
– user10419911
Nov 11 at 16:27
add a comment |
Lets say the user inputs 101 in the input, will that exit the code?
– Nuggethed2003
Nov 10 at 20:39
yes, then you have a problem :-) That's why in a real project you should do input checking an probably convert from types some semantic enum.
– user10419911
Nov 10 at 22:22
Yes I got it if fixed from the solution above. Changed it to String and it works
– Nuggethed2003
Nov 11 at 0:47
Yeah, that's the best solution here :)
– user10419911
Nov 11 at 16:27
Lets say the user inputs 101 in the input, will that exit the code?
– Nuggethed2003
Nov 10 at 20:39
Lets say the user inputs 101 in the input, will that exit the code?
– Nuggethed2003
Nov 10 at 20:39
yes, then you have a problem :-) That's why in a real project you should do input checking an probably convert from types some semantic enum.
– user10419911
Nov 10 at 22:22
yes, then you have a problem :-) That's why in a real project you should do input checking an probably convert from types some semantic enum.
– user10419911
Nov 10 at 22:22
Yes I got it if fixed from the solution above. Changed it to String and it works
– Nuggethed2003
Nov 11 at 0:47
Yes I got it if fixed from the solution above. Changed it to String and it works
– Nuggethed2003
Nov 11 at 0:47
Yeah, that's the best solution here :)
– user10419911
Nov 11 at 16:27
Yeah, that's the best solution here :)
– user10419911
Nov 11 at 16:27
add a comment |
up vote
0
down vote
You could just use the char
representations of the digits 1-4:
char choice = input.next().charAt(0);
switch (choice)
case '1':
aOT.areaOfTriangle();
break;
case '2':
hTDAH.hoursToDaysAndHours();
break;
case '3':
cTF.celciusToFahrenheit();
case '4':
System.out.println("Code not implemented");
break;
case 'e':
repeat = false;
break;
default:
System.out.println("");
break;
Thechar choice = input.nextInt().charAt(0);
didnt work it gave meCannot invoke charAt(int) on the primitive type int
– Nuggethed2003
Nov 10 at 20:40
@Nuggethed2003 meant to usenext()
, notnextInt()
, sorry. Edited and fixed.
– Mureinik
Nov 11 at 2:43
add a comment |
up vote
0
down vote
You could just use the char
representations of the digits 1-4:
char choice = input.next().charAt(0);
switch (choice)
case '1':
aOT.areaOfTriangle();
break;
case '2':
hTDAH.hoursToDaysAndHours();
break;
case '3':
cTF.celciusToFahrenheit();
case '4':
System.out.println("Code not implemented");
break;
case 'e':
repeat = false;
break;
default:
System.out.println("");
break;
Thechar choice = input.nextInt().charAt(0);
didnt work it gave meCannot invoke charAt(int) on the primitive type int
– Nuggethed2003
Nov 10 at 20:40
@Nuggethed2003 meant to usenext()
, notnextInt()
, sorry. Edited and fixed.
– Mureinik
Nov 11 at 2:43
add a comment |
up vote
0
down vote
up vote
0
down vote
You could just use the char
representations of the digits 1-4:
char choice = input.next().charAt(0);
switch (choice)
case '1':
aOT.areaOfTriangle();
break;
case '2':
hTDAH.hoursToDaysAndHours();
break;
case '3':
cTF.celciusToFahrenheit();
case '4':
System.out.println("Code not implemented");
break;
case 'e':
repeat = false;
break;
default:
System.out.println("");
break;
You could just use the char
representations of the digits 1-4:
char choice = input.next().charAt(0);
switch (choice)
case '1':
aOT.areaOfTriangle();
break;
case '2':
hTDAH.hoursToDaysAndHours();
break;
case '3':
cTF.celciusToFahrenheit();
case '4':
System.out.println("Code not implemented");
break;
case 'e':
repeat = false;
break;
default:
System.out.println("");
break;
edited Nov 11 at 2:42
answered Nov 10 at 20:10
Mureinik
177k22128197
177k22128197
Thechar choice = input.nextInt().charAt(0);
didnt work it gave meCannot invoke charAt(int) on the primitive type int
– Nuggethed2003
Nov 10 at 20:40
@Nuggethed2003 meant to usenext()
, notnextInt()
, sorry. Edited and fixed.
– Mureinik
Nov 11 at 2:43
add a comment |
Thechar choice = input.nextInt().charAt(0);
didnt work it gave meCannot invoke charAt(int) on the primitive type int
– Nuggethed2003
Nov 10 at 20:40
@Nuggethed2003 meant to usenext()
, notnextInt()
, sorry. Edited and fixed.
– Mureinik
Nov 11 at 2:43
The
char choice = input.nextInt().charAt(0);
didnt work it gave me Cannot invoke charAt(int) on the primitive type int
– Nuggethed2003
Nov 10 at 20:40
The
char choice = input.nextInt().charAt(0);
didnt work it gave me Cannot invoke charAt(int) on the primitive type int
– Nuggethed2003
Nov 10 at 20:40
@Nuggethed2003 meant to use
next()
, not nextInt()
, sorry. Edited and fixed.– Mureinik
Nov 11 at 2:43
@Nuggethed2003 meant to use
next()
, not nextInt()
, sorry. Edited and fixed.– Mureinik
Nov 11 at 2:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242827%2ftaking-int-input-and-parsing-into-char%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
76ec0wbEp4sY80xKPIwiAq2OCA0rBOOG x7eTpLIPVroJkO jjfj8DDdhn2blJ1 hlz695
3
And your question is?
– GBlodgett
Nov 10 at 19:52
1
while (repeat == true)
is the same aswhile (repeat)
andwhile (test == true ^ lengthTest != false)
is the same aswhile (test != !lengthTest)
which seems wrong or overly complicated.– Peter Lawrey
Nov 10 at 19:55
I would replace
choice = Integer.toString(input.nextInt()).charAt(0)
withchoice = input.nextInt()
– Peter Lawrey
Nov 10 at 19:55
I would also print any exception as it might be important as to which one.
– Peter Lawrey
Nov 10 at 19:56
@PeterLawrey yes you are correct. I made much more simple by removing
test
and now I am just doingwhile (!lengthTest);
– Nuggethed2003
Nov 11 at 0:45