System.in is an InputStream which is typically connected to keyboard input of console programs. In other words, if you start a Java application from the command line, and you type something on the keyboard while the CLI console (or terminal) has focus, the keyboard input can typically be read via System.in from inside that Java application. However, it is only keyboard input directed to that Java application (the console / terminnal that started the application) which can be read via System.in. Keyboard input for other applications cannot be read via System.in .
System.in is not used as often since data is commonly passed to a command line Java application via command line arguments, files, or possibly via network connections if the application is designed for that. In applications with GUI the input to the application is given via the GUI. This is a separate input mechanism from System.in.
System.out is a PrintStream to which you can write characters. System.out normally outputs the data you write to it to the CLI console / terminal. System.out is often used from console-only programs like command line tools as a way to display the result of their execution to the user. This is also often used to print debug statements of from a program (though it may arguably not be the best way to get debug info out of a program).
OutputStream os = newFileOutputStream("file.txt");
byteb[] = {65, 66, 67, 68, 69, 70};
//illustrating write(byte[] b) method
os.write(b);
//illustrating flush() method
os.flush();
//illustrating write(int b) method
for(inti = 71; i <75; i++)
{
os.write(i);
}
os.flush();
//close the stream
os.close();
}
}
ERROR
System.err is a PrintStream. System.err works like System.out except it is normally only used to output error texts. Some programs (like Eclipse) will show the output to System.err in red text, to make it more obvious that it is error text.
PROGRAM TO SOLVE SUDOKU # A Utility Function to print the Grid def print_grid(arr): for i in range ( 9 ): for j in range ( 9 ): print arr[i][j], print ( 'n' ) # Function to Find the entry in # the Grid that is still not used # Searches the grid to find an # entry that is still unassigned. If # found, the reference parameters # row, col will be set the location # that is unassigned, and true is # returned. If no unassigned entries # remains, false is returned. # 'l' is a list variable that has # been passed from the solve_sudoku function # to keep track of incrementation # of Rows and Columns def find_empty_location(arr, l): for row in range ( 9 ): ...
PROGRAM TO SOLVE SUDOKU class GFG { public static boolean isSafe( int [][] board, int row, int col, int num) { // Row has the unique (row-clash) for ( int d = 0 ; d < board.length; d++) { // Check if the number we are trying to ...
PROGRAM TO FIND REPEATING NUMBERS IN AN ARRAY class MAIN { public static void main(String args[]) { int numRay[] = { 0 , 4 , 3 , 2 , 7 , 8 , 2 , 3 , 1 }; for ( int i = 0 ; i < numRay.length; i++) { numRay[numRay[i] % numRay.length] = numRay[numRay[i] % numRay.length] + numRay.length; } System.out.println( "The repeating elements are : " ); for ( int i = 0 ; i < numRay.length; i++) { if (numRay[i] >= numRay.length* 2 ) { ...
Comments
Post a Comment