How to use the the count number somewhere else in java -


is there anyway in can place count variable. e.g. have count count number of lines. after want use number count has provided, , add number in variable can used somewhere else, e.g. add number, or find percentage or create pie chart using number.

public void totalcount12() throws filenotfoundexception  {         scanner file = new scanner(new file("read.txt"));         int count = 0;         while(file.hasnext()){             count++;             file.nextline();             }         system.out.println(count);         file.close(); 

i want use number in count, , use somewhere else (e.g method), have no idea how that.

thank you.

firstly recommend should complete javatutorial if new programming.

if define in class global variable(as attribute of class) out of method, can use in every method in class.

but if question using in everywhere of project different class, should use singleton design pattern;

public class classicsingleton {      private static classicsingleton instance = null;      protected classicsingleton() {      // exists defeat instantiation.      }      public static classicsingleton getinstance() {         if(instance == null)          {             instance = new classicsingleton();          }          return instance;      } } 

good luck!


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -