java - *insert word here* cannot be resolved to a variable -


i doing project school , can not seem find reason error. new programming , appreciate help. thank in advance.

import java.util.scanner;  public class lemonade {  public static void main(string[] args) {     scanner user = new scanner(system.in);     int lemons_per_pitcher = 12;     int spoons_per_bag = 1000;     int spoons_per_pitcher = 50;     system.out.println("enter amount of lemons have.");     int lemon = user.nextint();     system.out.println("enter amount of bags of sugar have.");     int bags = user.nextint();     int spoons = bags * 1000;     int sugar = spoons / 50;     int lemons2 = lemon / 12;     if( lemons2 > sugar){         int pitcher = lemons2;     }else{         int pitcher = sugar;     }     if( lemon < 12 || bags < 1){         system.out.println("you can make maximum of 0 pitchers");     } else{         system.out.println("this maximum amount of pitchers can         make is: " + pitcher);     } } 

}

pitcher local value can define in main method.

try this:

public static void main(string[] args) {         int pitcher;         scanner user = new scanner(system.in);         int lemons_per_pitcher = 12;         int spoons_per_bag = 1000;         int spoons_per_pitcher = 50;         system.out.println("enter amount of lemons have.");         int lemon = user.nextint();         system.out.println("enter amount of bags of sugar have.");         int bags = user.nextint();         int spoons = bags * 1000;         int sugar = spoons / 50;         int lemons2 = lemon / 12;         if (lemons2 > sugar) {             pitcher = lemons2;         } else {             pitcher = sugar;         }         if (lemon < 12 || bags < 1) {             system.out.println("you can make maximum of 0 pitchers");         } else {             system.out                     .println("this maximum amount of pitchers can         make is: "                             + pitcher);         }     } 

you can use variable in block defined it.

for instance:

{     int = 0; } i++; // error : there no in block 

in code:

if( lemons2 > sugar){     int pitcher = lemons2; }else{     int pitcher = sugar; } // pitcher no more exists after block 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -