Skip to content

penre/ICS3U1_Lesson_1_3_UserInput

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1.3 User Input

User Input Methods

readLine("prompt")

read a line of text from the console
i.e String colour = readLine("Enter your favourite colour? ");

readInt("prompt")

read an integer from the console
i.e int numGarage = readInt("Enter the number of garages: ");

readDouble("prompt")

read a double value from the console
i.e double avg = readDouble("Enter your grade average: ");

readBoolean("prompt")

read as boolean value from the console
i.e 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

vExample2

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

 
 
 

Contributors

Languages

  • Java 100.0%