0

I'm trying to determine if my ticket number has a "9" then change the price to 5. This is the code I have. The code itself compiles, but doesn't work as intended. I imagine it's because I'm using a wrong operator. If anyone could let me know how I could change it for it to work that'd be greatly appreciated.

for(int x=0; x<Integer.toString(e1.getNumber()).length(); x++)
{
    if(Integer.toString(e1.getNumber()).charAt(x) == 9)
     {
            System.out.println("The price is $5");
      }
  }

Thank you! I just had to change 9 to '9'! Its working now!!!

Milan Toth
  • 29
  • 4

2 Answers2

0

it depends on specific requirements. what if 9 is more then one times in string? what you do in such case? if you are sure that 9 appears once in your ticket price. just you next code.

if (yourString.contains("9")){
     yourString = yourString.replace("9", "5");
}
George Weekson
  • 483
  • 3
  • 13
0

Just had to put '9' so it looks for a char!

Milan Toth
  • 29
  • 4