java - Wont display int declared in if statement -



java - Wont display int declared in if statement -

package assignment_3_1; import java.util.scanner; public class assignment_3_1 { /** * @param args command line arguments */ public static void main(string[] args) { //create scanner scanner input = new scanner (system.in); //obtain bundle weight 1 system.out.print("enter bundle weight (in pounds): "); int packageweight1 = input.nextint(); double weightcalc1 = 5; double weightcalc2 = 15; double weightcalc3 = 34; double weightcalc4 = 45; double weightcalc5 = 60; double weightcalc6 = 60; double pricea = 12; double priceb = 14; double pricec = 17; double priced = 21; double pricee = 33; double pricef = 105; //if weightcalc1 >= packageweight1 base of operations charge 12 if (weightcalc1 >= packageweight1) { system.out.println("the base of operations charge : " + pricea); int baseprice = 12; } else { //if weightcalc2 >= packageweight1 base of operations charge 14 if (weightcalc2 >= packageweight1) { system.out.println("the base of operations charge is: " + priceb); int baseprice = 14; } else { //if weightcalc3 >= packageweight1 base of operations charge 17 if (weightcalc3 >= packageweight1) { system.out.println("the base of operations charge is: " + pricec); int baseprice = 17; } else { //if weightcalc4 >= packageweight1 base of operations charge 21 if (weightcalc4 >= packageweight1) { system.out.println("the base of operations charge is: " + priced); int baseprice = 21; } else { //if weightcalc5 >= packageweight1 base of operations charge 33 if (weightcalc5 >= packageweight1) { system.out.println("the base of operations charge is: " + pricee ); int baseprice = 33; } else { //if weightcalc6 < packageweight1 base of operations charge 105 if (weightcalc6 < packageweight1) { system.out.println("the base of operations charge is: " + pricef); int baseprice = 105; } else { system.out.println("re-run program"); } } } } } } //obtain zipcode system.out.println("enter 5 digit zip code: "); int zipcode = input.nextint(); double perc1 = 3999; double perc2 = 5000; double perc3 = 5999; double perc4 = 7000; //if perc1 < baseprice < perc2 if (perc1 < baseprice < perc2) { } } }

i declared int within of if statement , when started writing bottom part after big if statement tried using baseprice int declared within of if statement i've tried changing name of int , using double instead of int , nil work not sure im doing wrong.

the problem every int baseprice declared in it's own scope , not exist beyond scope. want declare int doubles, this:

double weightcalc1 = 5; double weightcalc2 = 15; double weightcalc3 = 34; double weightcalc4 = 45; double weightcalc5 = 60; double weightcalc6 = 60; double pricea = 12; double priceb = 14; double pricec = 17; double priced = 21; double pricee = 33; double pricef = 105; // declare baseprice here int baseprice;

then instead of having these blocks:

//if weightcalc1 >= packageweight1 base of operations charge 12 // base of operations cost exists within these brackes if (weightcalc1 >= packageweight1) { // base of operations cost exists within these brackes system.out.println("the base of operations charge : " + pricea); int baseprice = 12; }

you alter this:

//if weightcalc1 >= packageweight1 base of operations charge 12 if (weightcalc1 >= packageweight1) { system.out.println("the base of operations charge : " + pricea); baseprice = 12; }

java if-statement

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -