0% found this document useful (0 votes)
1 views8 pages

5 Week2 Java Input Output

The document discusses basic input and output operations in Java, focusing on the Console class for reading user input and the System.out methods for generating output. It highlights the use of readLine and readPassword methods for input, and explains how to print output using println, print, and printf methods. The content is part of a programming concepts course by Madhavan Mukund.

Uploaded by

nvnasritha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views8 pages

5 Week2 Java Input Output

The document discusses basic input and output operations in Java, focusing on the Console class for reading user input and the System.out methods for generating output. It highlights the use of readLine and readPassword methods for input, and explains how to print output using println, print, and printf methods. The content is part of a programming concepts course by Madhavan Mukund.

Uploaded by

nvnasritha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Basic input and output in Java

Madhavan Mukund
[Link]

Programming Concepts using Java


Week 2
Interacting with a Java program

We have seen how to print data


[Link]("hello, world");

How do we read data

Madhavan Mukund Basic input and output in Java Programming Concepts using Java 2/4
Reading input

Simplest to use is the Console class


Functionality similar to Python
input()

Madhavan Mukund Basic input and output in Java Programming Concepts using Java 3/4
Reading input

Simplest to use is the Console class Console cons = [Link]();


Functionality similar to Python String username =
input() [Link]("User name: ");
char[] passwd =
Defined within System [Link]("Password: ");
Two methods, readLine and
readPassword
readPassword does not echo
characters on the screen
readLine returns a string (like
Python input())
readPassword returns an array of
char — for security reasons

Madhavan Mukund Basic input and output in Java Programming Concepts using Java 3/4
Reading input

Simplest to use is the Console class Console cons = [Link]();


Functionality similar to Python String username =
input() [Link]("User name: ");
char[] passwd =
Defined within System [Link]("Password: ");
Two methods, readLine and
readPassword More general Scanner class
readPassword does not echo Allows more granular reading of input
characters on the screen Read a full line, or read an integer, . . .
readLine returns a string (like
Python input()) Scanner in = new Scanner([Link]);
readPassword returns an array of String name = [Link]();
char — for security reasons int age = [Link]();
....

Madhavan Mukund Basic input and output in Java Programming Concepts using Java 3/4
Generating output

[Link](arg) prints arg and goes


to a new line
Implicitly converts argument to a string

Madhavan Mukund Basic input and output in Java Programming Concepts using Java 4/4
Generating output

[Link](arg) prints arg and goes


to a new line
Implicitly converts argument to a string

[Link](arg) is similar, but does not


advance to a new line

Madhavan Mukund Basic input and output in Java Programming Concepts using Java 4/4
Generating output

[Link](arg) prints arg and goes


to a new line
Implicitly converts argument to a string

[Link](arg) is similar, but does not


advance to a new line
[Link](arg) generates formatted
output
Same conventions as printf in C
Read the documentation

Madhavan Mukund Basic input and output in Java Programming Concepts using Java 4/4

You might also like