Read Three Different Types
Easyjava
Learn the Concept: User InputRead an integer, a decimal number and a word (in that order), then print them in a formatted line.
Input: three whitespace-separated tokens — an int, a double, a word.
Output: one line: <word>: <int>, <double>
Example 1
Input
5 2.5 score
Output
score: 5, 2.5
- the double uses a dot as the decimal separator
Hint 1
Read each value as a token with sc.next() and convert it.
Hint 2
Assemble the output as word + ": " + n + ", " + d.
Scanner can read tokens of different kinds one after another. Convert each with the matching parse method, then build the output string. The double 1.0 prints with its .0 preserved.
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Read and Echo an AgeEasy · javaSolve Problem
- Sum of N NumbersEasy · javaSolve Problem
- Name Then AgeMedium · javaSolve Problem