Standard I/O - Loudoun County Public Schools

Standard I/O - Loudoun County Public Schools

Standard I/O Can we talk? Standard Output In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(text); There are different things we can do here other than outputting straight text. print vs println

Using println will have standard output put in a carriage return after the text while print will not. This code: System.out.println(AP CS); System.out.println( is the best ever!); Produces: AP CS is the best ever! This code:

System.out.print(AP CS); System.out.print( is the best ever!); Produces: AP CS is the best ever! Output of Variables We can output variables the same way that we can output text. This code: int numStudents = 13; System.out.println(numStudents);

Produces: 13 Usually though we want to output some text and we can do that with the + operator. This code: int numStudents = 13; System.out.println(Number of AP CS students: + numStudents); Produces: Number of AP CS students: 13

\Escape Sequence Sometimes we want to print something that is a little different from normal text. For that we have the escape key which is the backslash. Here is a listing of the more useful ones: 1. \n insert a newline 2. \r insert a carriage return 3. \t insert a tab 4. \ insert a single quote 5. \ insert a double quote 6. \\ - allows you to output a backslash

\Escape Sequence Example This code: System.out.println(I want sharks\n\t with \laser\ beams); Produces: I want sharks with laser beams Standard Input Standard Input is a bit more complicated than Standard Output but again JAVA provides us a

fairly straightforward way to do this. The sample we will use is as follows: import java.util.*; public class Interrogator { public static void main(String [] arg){ Scanner input = new Scanner(System.in); System.out.println("What is your name?"); String name = input.nextLine(); System.out.println("Hello " + name + ", I hope you doing well today."); } }

Import the important When programing in JAVA, we are provided a library of other code that we can make use of. But to do this, you must include an import statement to import the corresponding library. In this program we are using the Scanner class which is why we need: import java.util.*; After that we have a class and a main method declaration just like in Hello World

Scanner Class To use a Scanner we must declare it just like we would a primitive variable. But, because the Scanner is a class, we must also create an instance of it using the new operator. In this case, we named our Scanner input When we created it, we passed in System.in to the constructor method so that it scans input from the computers Standard input Scanner input = new Scanner(System.in);

Reading in information In this program we were interested in finding out the persons name so we used the method nextLine() to get the next line of text from Standard input. Once that line of text is returned from the method, we then use the assignment operator (=) to assign it to our variable name. String name = input.nextLine(); Methods of the Scanner Class

next() returns the next token (word) from the scanner nextLine() returns the next line of text from the scanner nextBoolean() reutrns the next boolean from the scanner nextInt() returns the next int from the scanner nextDouble() returns the next double from the scanner

Recently Viewed Presentations

  • Steroids Overall Organization of the Lecture Series  Introduction

    Steroids Overall Organization of the Lecture Series Introduction

    Steroids Overall Organization of the Lecture Series Introduction - Structure, Nomenclature, Conformation, Configuration Hypercholesterolemia - Cholesterol, Anti-hyperlipidemic Agents
  • NYSED Updates The Office of Curriculum and Instruction

    NYSED Updates The Office of Curriculum and Instruction

    Standards UpdateComputer Science / Digital Literacy * We encourage S/CDN members to provide comments and/or S/CDN to provide comments as an organization. Spring 2019. Review committee will review 2nd draft of Standards
  • Memory - Ms. G's Classroom

    Memory - Ms. G's Classroom

    Sensory Memory . Effortful processing begins with sensory memory. Iconic Memory: momentary sensory memory of visual stimuli; picture-image memory lasting no more than a few tenths of a second. George . Sperling (1960) showed his participants displays (above) for ....
  • gologit2: Generalized Logistic Regression Models for Ordinal ...

    gologit2: Generalized Logistic Regression Models for Ordinal ...

    Step 1: white meets the pl assumption (P Value = 0.7136) Step 2: ed meets the pl assumption (P Value = 0.1589) Step 3: prst meets the pl assumption (P Value = 0.2046) Step 4: age meets the pl assumption...
  • Bellwork 1/8 - Welcome to Ms. Mueller's Website

    Bellwork 1/8 - Welcome to Ms. Mueller's Website

    Canadian Robotic arm (Canadarm) Space walks, repairs, experiment monitoring. 6 laboratories. 2 U.S (NASA) 1 European Space Agency. 1 Japanese . 2 Russian. How does the ISS work? Pressurized modules. Solar panels . Heat produced from electronics. Oxygen:
  • Assessing effective interprofessional teamwork

    Assessing effective interprofessional teamwork

    Statutory Requirement. RCN (2007) on IPE " Effective collaboration in professional practice is necessary to underpin a patient-centred flexible health and social care service with staff working across social boundaries, in flatter non-hierarchical structures".
  • Nightingale Home Healthcare

    Nightingale Home Healthcare

    For purposes of benefit eligibility, under ยงยง1814(a)(2)(C) and 1835(a)(2)(A) of the Act, "intermittent" means skilled nursing care that is either provided or needed on fewer than 7 days each week or less than 8 hours of each day for periods...
  • Properties of Functions - Dornoch Mathematics

    Properties of Functions - Dornoch Mathematics

    The degree of the numerator > the degree of the denominator so we divide. x Hence y = x + 2 is an oblique asymptote. +2 -1 Page 110 Exercise 10 Questions 1(a), (b), (g), (f), (k), (l). TJ Exercise...