{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter2_4-InputOutput - Chapter 2 Java Fundamentals Input...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 2: Java Fundamentals Input and Output statements
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 2 Standard Output Window Using System.out , we can output multiple lines of text to the standard output window. The exact style of standard output window depends on the Java tool you use.
Background image of page 2
Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 3 The println Method We use println instead of print to skip a line. int x = 123, y = x + x; System.out.println( "Hello, Dr. Caffeine.“ ); System.out.print( " x = “ ); System.out.println( x ); System.out.print( " x + x = “ ); System.out.println( y ); System.out.println( " THE END“ );
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 4 Standard Input To input primitive data values, we use the Scanner class. 4 steps are needed to be able to use input primitive: Step 1: import the Scanner class: import Java.util.Scanner; Step 2 : declaring a reference variable of a Scanner Scanner read ; //we named the object read Step 3: creating an instance of the Scanner read = new Scanner (System.in); Step 4: use specific methods to enter data int x = read.nextInt();
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}