Input and Output in Java

Input and Output in Java

Input and Output in Java

Input and Output in Java

Published by: Anil K. Panta

Input and Output in Java

Reading Input using Scanner:

import java.util.Scanner;

Scanner sc = new Scanner(System.in);

int number = sc.nextInt();

Displaying Output:

  • System.out.println() – prints and moves to next line.

  • System.out.print() – prints without moving to next line.

  • System.out.printf() – prints formatted output.

Command-Line Arguments

  • Passed when running the program from terminal.

  • Accessible using String[] args in main() method.

Example:

java MyProgram arg1 arg2

We will get back to you via email or phone call