Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Basics Input / Output, and Primitive Data Types.

Similar presentations


Presentation on theme: "The Basics Input / Output, and Primitive Data Types."— Presentation transcript:

1 The Basics Input / Output, and Primitive Data Types

2 System.out System.out has two methods you can use for output:.println and.print The difference is where the carriage goes when the output is finished..print leaves the carriage at the end of the line whereas.println drops the carriage to the beginning of the next line. All typing between the (“ “) is called a literal String and is displayed on the console.

3 Escape Sequences Escape sequences are done inside a literal String. There are 3 escape sequences to help you make your text more aesthetically pleasing: \n returns the carriage to the next line. \” makes a literal quotation. \\ makes a literal backslash.

4 Input You are not expected to do any inputting on the A.P. test. If the testers want you to use any input, they will declare something like: String userInput = io.readln; * We will use input and I will show you how later.

5 Variables Variables are vessels for holding data, think of them as a bucket. Variables names must start with a letter, and by convention should start with a lower- case. If a variable is more than one word, there should be no spaces with each new word capitalized. For instance: myNewVariable.

6 Variable Types There are 3 primitive data types that we will start with: int, double, and boolean. These are like three different types of buckets that can hold 3 different types of things. int variables can hold integer values. double variables can hold rational values. boolean variables can only hold true or false

7 Variable Declaration Variables are declared by giving the variable a type (telling it which bucket it is). int number; double decimal; boolean isAnAwesomeGuy;

8 Variable Assignment Assignment is done using the = sign: number = 52; isAnAwesomeGuy = true; Assignment is done left to right so: 25 = number; is not a valid statement. Variables may be declared and assigned in the same statement: int myNewNum = 10;

9 Changing a value Variables are so named because they can change value. To reassign a value, simply use the = sign again. double someNum = 5.3; someNum = 2.4; * Notice the type was not given again- once a variable is declared it may never change (bucket) types so it is redundant to redeclare.

10 Your Turn! Define a class that is your name, and declare a main method inside of it(leave about 6 lines of space for code. Output a line that says: Hello and then returns the cursor to the next line. Output in one statement something that says: I am so \ darn “Happy” to be here!

11 Your Turn cont. Declare 3 variables called integerNumber, decimalNumber, and booleanValue with the values: -1025, 27.384, and false respectively. Output the values. Change integerNumber to 0 and booleanValue to true. Output the values.


Download ppt "The Basics Input / Output, and Primitive Data Types."

Similar presentations


Ads by Google