Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Digit Extractor Help
#2
This problem may be occurring because strings cannot necessarily be compared using "==". The "==" operator is only used when comparing integer values. Thus, you will want to use the String.equals() method in order to compare strings. You also do not need to have multiple scanner objects. The same scanner can be used more than once, so you can also remove the second Scanner object.

So, the new piece of code would look like this:
[code2=java]import java.util.Scanner;
public class DigitExtratorTester {

static Scanner input = new Scanner(System.in);

public static void main(String[] args)
{
System.out.println("Welcome to the Digit Extractor. Please enter 5 digits of your choice:");
String in = input.nextLine();
System.out.println("Would you like it done either" + "\n" + "A) Mathematically" + "\n" + "or B)Conceptually?" + " \n" + "*Please choose either A or B*");
String in2 = input.nextLine();
if (in2.equals("A"))
{
DigitExtractor demath = new DigitExtractor(Integer.parseInt(in));
demath.ReturnInvertedOrderByMath();
}
else if (in2.equals("B"))
{
DigitExtractor deconceptual = new DigitExtractor(in);
deconceptual.ReturnInvertedOrderByString();
}
else
{
System.out.println("You done goof my friend!");
}

}

}[/code2]
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Digit Extractor Help - by MPratik - 06-28-2013, 11:12 AM
Re: Digit Extractor Help - by brandonio21_phpbb3_import2 - 07-01-2013, 09:33 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)