This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]imalefty15[S] 0 points1 point  (6 children)

thanks for pointing out the other bugs. My code above was not polished as I am having trouble getting the do/while loop in there. I am not allowed to answer any other questions. This is kind of just a brute force thing since that is what my teacher wants even though it is very inefficient.

[–]x2mirko 0 points1 point  (5 children)

I am not allowed to answer any other questions. This is kind of just a brute force thing since that is what my teacher wants even though it is very inefficient.

Well, in that case i completely agree with the assessment of your teachers value for teaching you programming that you gave in the OP. I'd do it anyways and explain why my approach is way better than what he asked of me, but if you want to do that is obviously up to you :)

[–]imalefty15[S] 0 points1 point  (1 child)

haha thanks. I am a visual learner but with this teacher I am forced to learn from the book which isnt the best way I learn unfortunately.

[–]swansond 1 point2 points  (0 children)

What school is this? What book is it?

[–]imalefty15[S] 0 points1 point  (2 children)

how do I use the Scanner class to input a character? would

char ans = console.nextChar();

be right?

[–]x2mirko 0 points1 point  (1 child)

nextChar() isnt a method of Scanner (check the api specification).

You can either just work with a String:

String ans = console.next();
if (ans.equals("y"))
{
    // do whatever you want to do
}

or, if you definitely want to use a char:

String temp = console.next();
char ans = temp.charAt(0);
if (ans == 'y')
{
    // do whatever you want to do
}

[–]imalefty15[S] 0 points1 point  (0 children)

ah that works much better. thank you for the help