0% found this document useful (0 votes)
17 views

Introduction To Java-5 Input, Randon Number and Class

The document discusses input and output in Java, including using System.in to read from the console, creating a Scanner object from System.in, Scanner methods for reading tokens, and using System.out for output with print and println methods.

Uploaded by

Sumit Tripathi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Introduction To Java-5 Input, Randon Number and Class

The document discusses input and output in Java, including using System.in to read from the console, creating a Scanner object from System.in, Scanner methods for reading tokens, and using System.out for output with print and println methods.

Uploaded by

Sumit Tripathi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Input/Output

© 2014 Goodrich, Tamassia, Goldwasser Java Primer 2 1


Simple Input
 There is also a special object, System.in, for performing input
from the Java console window.
 A simple way of reading input with this object is to use it to
create a Scanner object, using the expression
new Scanner(System.in)

© 2014 Goodrich, Tamassia, Goldwasser Java Primer 2 2


Simple Input

© 2014 Goodrich, Tamassia, Goldwasser Java Primer 2 3


java.util.Scanner Methods
 The Scanner class reads the input stream and
divides it into tokens, which are strings of
characters separated by delimiters.

© 2014 Goodrich, Tamassia, Goldwasser Java Primer 2 4


Simple Output
 Java provides a built-in static object, called
System.out, that performs output to the “standard
output” device, with the following methods:

© 2014 Goodrich, Tamassia, Goldwasser Java Primer 2 5



Import java.lang.Math;

public class RanNo

{

public static void main( String args[])

{

double x = Math.random();

// x will be 0 to 1 but not 1

int dice =(int)( x *(max – min+1) + min);

}
}

You might also like