Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Podcasts & Audio Briefings9to5Google: The Sideload 046: Frictionmaxxing with Allison Johnson(29.09.2026 um 22:31 Uhr)
•
YouTube Security VideosNASA's SpaceX Crew-13 Prelaunch News Conference (Sept. 30, 2026)(22.09.2026 um 22:14 Uhr)
•
YouTube Security VideosNASA's SpaceX Crew-13 Launch(29.09.2026 um 00:25 Uhr)
•
Windows Tipps & SecurityMicrosoft Releases WSL Containers for Windows 11(29.09.2026 um 22:37 Uhr)
•
Unix & Linux ServerSecurity: Mangelnde Rechteprüfung in KDE Plasma (Ubuntu)(29.09.2026 um 23:50 Uhr)
•
Unix & Linux ServerSecurity: Mehrere Probleme in amazon-cloudwatch-agent (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Pufferüberlauf in corosync (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Ausführen beliebiger Kommandos in perl-DBI (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Zwei Probleme in cjose (SUSE)(30.09.2026 um 00:10 Uhr)
••
Podcasts & Audio Briefings9to5Google: The Sideload 046: Frictionmaxxing with Allison Johnson(29.09.2026 um 22:31 Uhr)
•
YouTube Security VideosNASA's SpaceX Crew-13 Prelaunch News Conference (Sept. 30, 2026)(22.09.2026 um 22:14 Uhr)
•
YouTube Security VideosNASA's SpaceX Crew-13 Launch(29.09.2026 um 00:25 Uhr)
•
Windows Tipps & SecurityMicrosoft Releases WSL Containers for Windows 11(29.09.2026 um 22:37 Uhr)
•
Unix & Linux ServerSecurity: Mangelnde Rechteprüfung in KDE Plasma (Ubuntu)(29.09.2026 um 23:50 Uhr)
•
Unix & Linux ServerSecurity: Mehrere Probleme in amazon-cloudwatch-agent (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Pufferüberlauf in corosync (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Ausführen beliebiger Kommandos in perl-DBI (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Zwei Probleme in cjose (SUSE)(30.09.2026 um 00:10 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

Scanner Class

Class in Java Definition The Scanner class is a predefined class in Java used to take input from the user. It belongs to: java.util package Why Scanner? It is used to read: int double float String boolean long etc. How to Use…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Class in Java



Definition

The Scanner class is a predefined class in Java used to take input from the user.

It belongs to:

java.util package



Why Scanner?

It is used to read:

int

double

float

String

boolean

long

etc.



How to Use Scanner



Step 1: Import the package



import java.util.Scanner;



Step 2: Create Scanner Object



Scanner sc = new Scanner(System.in);



✔ System.in → Takes input from keyboard

✔ sc → Object name



Step 3: Take Input



int age = sc.nextInt();



String name = sc.nextLine();



double salary = sc.nextDouble();



Important Concept:



If you write:



int age = sc.nextInt();

String name = sc.nextLine();



The nextLine() may get skipped because nextInt() does not consume the newline.



Correct way:



int age = sc.nextInt();

sc.nextLine(); // consume leftover newline

String name = sc.nextLine();



Common Scanner Methods



nextInt()-Integer

nextDouble() - Decimal number

next() - Single word

nextLine() - Full sentence

nextBoolean() - true/false



Always Close Scanner



sc.close();



Example:

If we want to get the 5 subject marks from user and print the total we can use the scanner class and achieve this.

import java.util. Scanner;

public class TotalMarks {




    public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter Tamil mark:");
int tamil = sc.nextInt();

System.out.println("Enter English mark:");
int english = sc.nextInt();

System.out.println("Enter Maths mark:");
int maths = sc.nextInt();

System.out.println("Enter Science mark:");
int science = sc.nextInt();

System.out.println("Enter Social mark:");
int social = sc.nextInt();
sc.nextLine();

System.out.println("Student name");

String name = sc.nextLine();

int total = tamil + english + maths + science + social;
System.out.println("Total Marks" + total);
System.out.println("Student name"+name);

sc.close(); // Good practice
}
}


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Scanner Class

Thematisch verwandte Begriffe: Scanner, Class · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-102253 | iperf3 versions prior to 3.22 contains a denial of service vulnerabilit…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag