Variable scope
Download
1 / 4

Variable Scope - PowerPoint PPT Presentation


  • 112 Views
  • Uploaded on

Variable Scope. Brackets, brackets…. brackets. Variable Scope. /** * HelloWorld --- program that prints something to the screen. * @author Blanca Polo */ public class HelloWorld{ public static void main (String arg[ ]){ String s = “Hello World!!!”;

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Variable Scope' - bertha


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Variable scope

Variable Scope

Brackets, brackets…. brackets


Variable scope1
Variable Scope

/**

* HelloWorld --- program that prints something to the screen.

* @author Blanca Polo

*/

public class HelloWorld{

public static void main (String arg[ ]){

String s = “Hello World!!!”;

System.out.println( s );

}

}


Variable scope2

public class ParseI{

public static void main (String arg[ ])throws Exception{

InputStreamReader isr = new InputStreamReader(System.in);

BufferedReader br = new BufferedReader(isr);

int iNum = 0;

String sUserInput = "";

System.out.println("Enter a number please ");

sUserInput = br.readLine( );

System.out.println("You typed " + sUserInput);

//risky code

try{

iNum = Integer.parseInt(sUserInput);

System.out.println("Thanks for the number!!! ");

}

catch(NumberFormatException nfe){

System.out.println("I asked for a number, dummy!!");

}

System.out.println("- - - - the end - - - - ");

} //main

} // class

VariableScope


Variable scope3

VarScope.java:22: cannot find symbol

symbol : variable sUserInput

location: class VarScope

System.out.println("and you typed "+ sUserInput);

^

1 error

public class ParseI{

public static void main (String arg[ ])throws Exception{

InputStreamReader isr = new InputStreamReader(System.in);

BufferedReader br = new BufferedReader(isr)

//risky code

try{

String sUserInput = "";

System.out.println("Enter a number please ");

sUserInput = br.readLine( );

System.out.println("You typed " + sUserInput);

int iNum = 0;

iNum = Integer.parseInt(sUserInput);

System.out.println("Thanks for the number!!! ");

}

catch(NumberFormatException nfe){

System.out.println("I asked for a number, dummy!!");

System.out.println(”and you typed “+ sUserInput);

}

System.out.println("- - - - the end - - - - ");

} //main

} // class

VariableScope


ad