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.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
18 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.
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)
java.util.Scanner Methods The Scanner class reads the input stream and divides it into tokens, which are strings of characters separated by delimiters.
Simple Output Java provides a built-in static object, called System.out, that performs output to the “standard output” device, with the following methods:
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); } }