Presentation is loading. Please wait.

Presentation is loading. Please wait.

Input, Variables, and Mathematical Expressions

Similar presentations


Presentation on theme: "Input, Variables, and Mathematical Expressions"— Presentation transcript:

1 Input, Variables, and Mathematical Expressions
By James H

2 Input Input definition:
To enter information or data into a form of input element such as a textbox, text field, text entry box etc. The user can input anything into these input elements as data This data can be put into a variable box for the program to remember and use later.

3 Basic Input Commands Import the scanner library of codes at the top: Import Java.util.scanner; Set up scanner class: Scanner scan1=new Scanner(System.in); Prompt respond to input request: System.out.println("What is your name?:"); Scan and input it in a variable: a=scanl.nextInt(); b=scanl.nextDouble(); c=scanl.nextLine();

4 Variables Variables are storable boxes located in the computer’s RAM (Random Access Memory) Variables can be labeled under any name by the programmer These variables can store many forms of values such as text, numbers and decimals. Values can be either predetermined by the programmer or values that the user has inputted as well.

5 Basic Variable Commands
Declares an integer variable int num=666; Declares a double variable (decimals) Double num=6.8; Declares a string variable String pricey= “wow”;

6 Mathematical Expression
Mathematical expressions are commands that allow the program to perform basic math on variables such as addition, subtraction, multiplication etc. Basic Commands: Perform addition on “num” and store it as a new variable Int num2=num+1; Perform subtraction on “num” and store it as a new variable Int num2=num-1; Perform multiplication on “num” and store it as a new variable Int num2=num*1; Perform division on “num” and store it as a new variable Int num2=num/1;

7 Purpose Asking the user to input data allows the program to use this information at anytime by accessing the variable assigned Since the user can input any form of data, it adds variation to how the program will run Depending on what the user inputs into a variable, the program can respond differently to what the user has inputted. The program can also manipulate data in variables, for example if the user enters a number you can add, subtract, multiply etc. that value Thus, the program has infinite possibility of what data it can store, manipulate, and output.

8 Command Example: Import Java.util.scanner; (assume this is at the very top) String name=""; Int age=0; Scanner scanl=new Scanner(System.in); System.out.println("What is your name?:"); name=scanl.nextString(); System.out.println("How old are you?:"); age=scanl.nextInt(); Int age2 = age+1; System.out.println("Your name is “+name+” and you are turning “+age2+” next year.”);

9 The End


Download ppt "Input, Variables, and Mathematical Expressions"

Similar presentations


Ads by Google