if statement - Java Nested If Help (The Logic is seemingly correct but always outputs the same thing) -


i trying use nested if statements in order determine value of variable , code, correct results not occurring. please can help? using array hold values being compared input (using in order show "knowledge" of java). then, calling function testflower() initialize logic. not able identify in logic went wrong. every time inputted, result printed out print line "roses". returned string should change when different flower names typed in not occur. have ideas on issue in code?

import java.util.scanner;  public class {      public final double tax = 1.127;     public final double s_basket = 10, m_basket = 20, l_basket = 30, s_elephant = 15, l_elephant = 30,               s_seal = 15, l_seal = 30, s_bear = 15, l_bear = 30, s_penguin = 15, l_penguin = 30,               mchocolate = 15, wchocolate = 20, dchocolate = 30;      public string flowers[] = {"rose", "tulip", "daisy", "daffodil", "sunflower", "orchid"};      public scanner s = new scanner(system.in);      public string flowertype;       public void testflower() {         if (!(flowertype.equals(flowers[1]))) {             if (!(flowertype.equals(flowers[2]))) {                 if (!(flowertype.equals(flowers[3]))) {                     if (!(flowertype.equals(flowers[4]))) {                         if (!(flowertype.equals(flowers[5]))) {                             flowertype = "roses";                             system.out.println(flowertype);                         } else {                             flowertype = "orchids";                             system.out.println(flowertype);                         }                     } else {                         flowertype = "sunflowers";                         system.out.println(flowertype);                     }                 } else {                     flowertype = "daffodils";                     system.out.println(flowertype);                 }             } else {                 flowertype = "daises";                 system.out.println(flowertype);             }         } else {             flowertype = "tulips";             system.out.println(flowertype);         }     }      public static void main(string[] args) {         a = new a();          system.out.println("hello! welcome flower shop! type of flowers want? (rose, tulip, daisy, daffodil, sunflower, orchid)");         a.flowertype = a.s.nextline();         a.flowertype.touppercase();          a.testflower();      } } 

first, learn use debugger , inspect values such flowertype. doing have shown uppercasing doesn't expect: have assign result variable, since string immutable.

a.flowertype = a.s.nextline(); a.flowertype = a.flowertype.touppercase(); 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -