title: how to take value from variable inside If Statement in java
body: <p>I declared a variable in public class, then I assigned the variable with if statement, but when I calculated it didn't get the value from if statement. How to solve it?
  Here the full code <a href="https://pastebin.com/yuaMx4Mk" rel="nofollow noreferrer">https://pastebin.com/yuaMx4Mk</a> Thank You</p>
  
  <pre><code>    double doubleJarak=Double.parseDouble(jarak);
      double doublewaktu=Double.parseDouble(waktu);
      //SPinner Code
      MaterialSpinner spinner = (MaterialSpinner) findViewById(R.id.spinner);
      spinner.setItems("Premium Rp 7.000", "Pertalite Rp 7.650", "Pertamax Rp 9.850", "Pertamax Turbo Rp 11.200");
      spinner.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener&lt;String&gt;() {
  
          @Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
              //Snackbar.make(view, "Clicked " + item, Snackbar.LENGTH_LONG).show();
              if(position==0)
                  hargaBBM=7000;
              else if(position==1)
                  hargaBBM=7650;
              else if(position==2)
                  hargaBBM=9850;
              else
                  hargaBBM=11200;
          }
      });
      MaterialSpinner spinner2 = (MaterialSpinner) findViewById(R.id.spinner2);
      spinner2.setItems("Honda", "Yamaha", "Kawasaki", "Suzuki", "Lainnya");
      spinner2.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener&lt;String&gt;() {
  
          @Override public void onItemSelected(MaterialSpinner view, int position2, long id, String item) {
              //Snackbar.make(view, "Clicked " + item + position2, Snackbar.LENGTH_LONG).show();
              if (position2==0){
                  MaterialSpinner spinner3 = (MaterialSpinner) findViewById(R.id.spinner3);
                  spinner3.setItems("Revo 110 FI", "Blade 125 FI", "Supra X 125 FI");
                  spinner3.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener&lt;String&gt;() {
                      @Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
                          //Snackbar.make(view, "Clicked " + item, Snackbar.LENGTH_LONG).show();
                          if(position==0){
                              iritHonda=62200;
                          }else if(position==1){
                              iritHonda=61800;
                          }else if(position==2){
                              iritHonda=61800;
                          }
                      }
                  });
  
              }
          }
      });
      totalHarga=iritHonda*hargaBBM;
      TextView Harga=(TextView)findViewById(R.id.totalHarga);
      Harga.setText(Double.toString(totalHarga));
  
  }
  </code></pre>
  
  <p>}</p>