Skip to content

SACHSTech/ICS3U1_Lesson_1_3_UserInput

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1.3 User Input

User Input Methods

readLine("prompt")

  • Read a line of text from the console

Example:

String colour = readLine("Enter your favourite colour? ");

readInt("prompt")

  • Read an integer from the console

Example:

int numGarage = readInt("Enter the number of garages: ");

readDouble("prompt")

  • Read a double value from the console

Example:

double avg = readDouble("Enter your grade average: ");

readBoolean("prompt")

  • Read as boolean value from the console

Example:

boolean pancakes = readBoolean("Do you like pancakes(true/false)");

General CodeHS User Input Template (from variable declaration)

<dataType> <variableName> = <readCommand>("<prompt>");

Example 1

Create a program UserInput.java that asks for the following information and then outputs the information back to the console

  • name
  • age
  • current mark
  • has been assigned a locker

Example Run

Enter your name: John
Enter your age: 16
Enter your current mark: 92.3
Have you been assigned a locker (true/false): true

Name: John
Age: 16
Current Mark: 92.3
Locker Assigned: true

Example 2

Modify UserInput.java so that it prompts for a first name and last name

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages