inside static method u cannot call a non-static variable. make the variable static...
s.subramanian IonIdea Enterprise Solutions Bangalore ----- Original Message ----- From: "[Vaishali S. Pandya]" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, May 13, 2002 10:40 AM Subject: Re: how to use global variable? > Can't make a static reference to nonstatic variable myval > > this is the error i get in this code > > <HTML> > <HEAD> > <TITLE> Factorial </TITLE> > </HEAD> > <BODY> > <%! > int myval[]= new int[100]; > int v=0; > %> > <% > int a=0; > out.println(v); > for (a=0;a<v;a++){ > out.println(myval[a]); > } > out.println(fact(5)); > %> > <%! > public static int fact(int i){ > myval[v++] = i; > if (i==1){ > return i; > } > return i*fact(i-1); > } > %> > </BODY> > </HTML> > > > > By defining the variable like this > > <%! > file://declare global variable here > %> > > -----Original Message----- > From: [Vaishali S. Pandya] [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 13, 2002 10:12 AM > To: [EMAIL PROTECTED] > Subject: how to use global variable? > > > hello all > good morning > as my prev que, > i tried to use function and not able to use out.println in function > so now i want to use a global array and want to add all values in array and > will print that array in main code > but i don't know how to make an array global. > > see the code > > <HTML> > <HEAD> > <TITLE> Factorial </TITLE> > </HEAD> > <BODY> > <%! > public static int fact(int i){ > // System.out.println(i); > myval[v++] = i; > if (i==1){ > return i; > } > return i*fact(i-1); > } > %> > <% > for(a=0;a<v;a++) > out.println(myval[a]); > out.println(fact(5)); > %> > </BODY> > </HTML> > > here array myval and int v must be global so i can use it in main code as > well as in function > how? > > ThankX > Vaishali > Reliance Ind Ltd > Ahmedabad > > =========================================================================== > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". > Some relevant FAQs on JSP/Servlets can be found at: > > http://archives.java.sun.com/jsp-interest.html > http://java.sun.com/products/jsp/faq.html > http://www.esperanto.org.nz/jsp/jspfaq.jsp > http://www.jguru.com/faq/index.jsp > http://www.jspinsider.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com