🎴 Flashcard Mode

Java Programming with Database Connectivity

Card1 / 19
Mastered0
Review0
QuestionClick to flip

import java.util.Scanner; public class ScannerTest { public static void main(String[] args) { Scanner scanner = new Scanner("hello 1 2.00 false"); scanner.useDelimiter(" "); String str = scanner.next(); int anInt = scanner.nextInt(); float aFloat = scanner.nextFloat(); boolean booleanValue = scanner.nextBoolean(); System.out.println(str + ":" + anInt + ":" + aFloat + ":" + booleanValue); } }

AnswerClick to flip back
A
The program will output 'hello:1:2.0:false'
💡 Explanation:

The Scanner reads each token sequentially using space as delimiter: 'hello' as String, 1 as int, 2.00 as float (formatted as 2.0), and false as boolean. The println concatenates these with colons between values.

Change Mode