Curriculum
Input and Output with Scanner and System.out in Java are essential concepts for building interactive Java applications. Every software application requires user input and output operations to process information and display results.
In this Core Java course in Jaipur, students will learn how to take user input using Scanner class and display output using System.out methods. These concepts are important for Java programming, backend development, desktop applications, banking systems, billing software, and enterprise application development.
Understanding input and output in Java helps students create dynamic programs that interact with users effectively.
Input and output operations allow programs to:
Examples:
Java provides:
System.out
for displaying output on the console screen.
The most commonly used methods are:
System.out.println() prints output and moves the cursor to the next line.
class OutputExample {
public static void main(String[] args) {
System.out.println("Welcome to Java");
System.out.println("Core Java Course");
}
}
Welcome to Java
Core Java Course
System.out.print() prints output on the same line.
class PrintExample {
public static void main(String[] args) {
System.out.print("Java ");
System.out.print("Programming");
}
}
Java Programming
System.out.printf() is used for formatted output.
class PrintfExample {
public static void main(String[] args) {
int age = 22;
System.out.printf("Age: %d", age);
}
}
Age: 22
Scanner class in Java is used to take input from the user.
Scanner belongs to:
java.util package
To use Scanner, developers must import it.
import java.util.Scanner;
Scanner sc = new Scanner(System.in);
Here:
import java.util.Scanner;
class InputExample {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your age: ");
int age = sc.nextInt();
System.out.println("Your age is: " + age);
}
}
Enter your age: 22
Your age is: 22
import java.util.Scanner;
class StringInput {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = sc.nextLine();
System.out.println("Welcome " + name);
}
}
import java.util.Scanner;
class DoubleInput {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter salary: ");
double salary = sc.nextDouble();
System.out.println("Salary: " + salary);
}
}
| Method | Purpose |
|---|---|
| nextInt() | Reads integer |
| nextDouble() | Reads decimal number |
| nextFloat() | Reads float value |
| next() | Reads single word |
| nextLine() | Reads full line |
| nextBoolean() | Reads boolean value |
Programs become interactive when input and output are combined.
import java.util.Scanner;
class StudentDetails {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter name: ");
String name = sc.nextLine();
System.out.print("Enter marks: ");
int marks = sc.nextInt();
System.out.println("Student Name: " + name);
System.out.println("Marks: " + marks);
}
}
Scanner class is important because it helps:
Input and output operations are used in:
Incorrect:
Scanner sc = new Scanner(System.in);
without import statement causes error.
Entering text instead of integer causes:
InputMismatchException
Beginners often face issues when combining these methods.
Scanner should be closed after use.
Example:
sc.close();
Understanding input and output helps students:
In this lesson, students learned:
These concepts are essential for Java programming and application development.
Scanner class is used to take input from the user.
Scanner belongs to java.util package.
It is used to print output and move to the next line.
print() keeps output on the same line, while println() moves to the next line.
Input allows applications to accept user data dynamically.
It occurs when the entered input type does not match the expected data type.
WhatsApp us