java - Accessing a variable from inside a do-while loop -


how can access variable inside do-while loop in java?

the code below writes out value until value entered not between 0 , 10.

here code :

import java.util.scanner;  public class dowhilerange {     public static void main(string[] args) {         do{             system.out.println("enter number between 0 10");             scanner in = new scanner(system.in);             int = in.nextint();                 int total +=0;         }while (a>0 && a<10);          system.out.println("loop terminated");         system.out.println("the total : "+total);     } } 

the loop continues ask input long input between 0 , 10. once other number entered loop terminates , displays total of inputted numbers.

try (declare variable outside loop):

    int = -1;     do{         system.out.println("enter number between 0 10");         scanner in = new scanner(system.in);         = in.nextint();     }while (a>0 && a<10); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -