39.8k views
0 votes
1) Prompt the user to enter two words and a number, storing each into separate variables. Then, output those three values on a single line separated by a space. (Submit for 1 point) Enter favorite color: yellow Enter pet's name: Daisy Enter a number: 6 You entered: yellow Daisy 6

1 Answer

4 votes

Answer:

import java.util.Scanner;

public class TestClock {

public static void main(String[] args) {

Scanner in = new Scanner (System.in);

System.out.print("Enter favorite color:");

String word1 = in.next();

System.out.print("Enter pet's name:");

String word2 = in.next();

System.out.print("Enter a number:");

int num = in.nextInt();

System.out.println("you entered: "+word1+" "+word2+" "+num);

}

}

Step-by-step explanation:

Using Java Programming language

  1. Import the Scanner class
  2. create an object of the scanner class
  3. Prompt user to enter the values for the variables (word1, word2, num)
  4. Use String concatenation in System.out.println to display the output as required by the question.

User Sadiksha Gautam
by
4.4k points