1 / 4

Understanding Variables and Compiler Errors

Variables are like memory stations in computers that store values. Learn how to declare, initialize, and use them properly to avoid compiler errors.

theis
Download Presentation

Understanding Variables and Compiler Errors

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Variables variable: A piece of the computer's memory that is given a name and type, and can store a value. Like preset stations on a car stereo, or cell phone speed dial: Steps for using a variable: Declare it - state its name and type Initialize it - store a value into it Use it - print it or use it as part of an expression

  2. Compiler errors A variable can't be used until it is assigned a value. int x; System.out.println(x); // ERROR: x has no value You may not declare the same variable twice. int x;int x;// ERROR: x already exists int x = 3;int x = 5; // ERROR: x already exists How can this code be fixed?

  3. Loop walkthrough for (int count = 1; count <= 4; count = count + 1) { System.out.println("Hello World!"); } System.out.println("Whoo!"); Output: Hello World! Hello World! Hello World! Hello World! Whoo! 2 4 1 3 5 1 2 3 4 5

More Related