java beginner - cannot find symbol -


this question has answer here:

i beginner in java , trying create program recieves input numbers in terminal, , continuously ask new numbers until 0 entered. after 0 has been entered want program summarize of numbers , plus them together. when try compile program error:

enter image description here

heres code:

import java.util.scanner;  public class sumtall {     public static void main(string[] args) {         scanner tallscanner = new scanner(system.in);         int tall = 0;         int tall1;          system.out.println("write number:");         tall1 = integer.parseint(tallscanner.nextline());          while(tall1 > 0) {             system.out.println("write number:");             tall1 = integer.parseint(tallscanner.nextline());             int tall2 = tall + tall1;         }         if(tall1 == 0) {             system.out.println(tall2);         }     } } 

you declared tall2 in while block declare outside while. stick block in case belong while block trying access variavle tall2 out side while that's reason can see error. hope you.

i changed declaration part out side.

import java.util.scanner;  public class sumtall {     public static void main(string[] args) {         scanner tallscanner = new scanner(system.in);         int tall = 0;         int tall1,tall2;          system.out.println("write number:");         tall1 = integer.parseint(tallscanner.nextline());          while(tall1 > 0) {             system.out.println("write number:");             tall1 = integer.parseint(tallscanner.nextline());             tall2 = tall + tall1;         }         if(tall1 == 0) {             system.out.println(tall2);         }     } } 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -