Term 1: Lesson 3 - User Input and Variables

¡Supera tus tareas y exámenes ahora con Quizwiz!

Variable

A name for a spot in the computer's memory; this value can change while the program runs

What is Input?

Input is pulling the information into the computer

The Scanner class

Scanner scan = new Scanner(System.in); This class adds input to your Java programs

What is wrong with the following code? String s = nextLine();

Should be: String s = scan.nextLine(); because you have to call the nextLine() method from a Scanner type object.

Declare

To create the variable in memory; necessary to let Java know what types of information it will store

What happens when we declare a variable?

We tell the computer to allocate some space in memory for something. We tell it what the name of the thing will be, so it knows how to find it later, and what the type of the thing will be, so it knows how much space to set aside:

concatenation

When we glue a literal String and a String variable together using a plus sign

What is wrong with this code? String s; System.out.println(s);

You cannot print a String without setting its value. The string, s, needs to be initialized with a value before it can be printed.

For Input to work you need what?

You have to have a spot in memory to hold this value

Which character do you use to print to the next line?

\n

Which is used to insert a tab character?

\t

Variables can ________ in programming, as they are just containers.

change

We can think of variables as

containers in memory.

variable name rules

they cannot contain spaces, cannot start with numbers, and cannot share the names of commands, such as "print".

Scanner allows what?

us to take user input and incorporate it into our programs.

While n.1, int, 1test, and a name are illegal, what is a legal variable name in Java?

value because it is not a special (aka "reserved") word in Java and can be used in variable names.

What do we do when we want to print things out?

we can combine literal Strings (things in quotation marks) and variables

What happens when we use a Scanner to take input?

we read a String from the keyboard and store it as a variable.


Conjuntos de estudio relacionados

Test 2 review Music appreciation

View Set

Combo with "Research methods-CITI" and 1 other

View Set

MY Chemistry Workshops and Quizzes

View Set

Module 7 Assignment 1 NCLEX-PN Custom EAQ: Urinary Disorders

View Set

Am. Hist. II ~ Manhattan Project Questions

View Set

AUD Section 4 - Forming Conclusions and Reporting

View Set

Econ 302 Study for Finals GDP, Money, AD/ AS

View Set

PSY350 Module 6: Dissociative Disorders

View Set

WORLD HISTORY 1001: THE BEGINNINGS OF HUMAN SOCIETY Test Study Guide

View Set