Answer:
import java.util.Scanner;
public class BasicInput {
public static void main(String[] args) {
//Create an object of the Scanner class
Scanner scnr = new Scanner(System.in);
//Define int and double variables
int userInt;
double userDouble;
//Define char and string variables similarly
char userChar;
String userString;
//Prompt the user to enter an integer
System.out.println("Enter integer:");
//Store the input in the integer variable
userInt = scnr.nextInt();
//Prompt the user to enter a double
System.out.println("Enter double:");
//Store the input in the double variable
userDouble = scnr.nextDouble();
//Prompt the user to enter a char
System.out.println("Enter char:");
//Store the input in the char variable
userChar = scnr.next().charAt(0);
//Prompt the user to enter a string
System.out.println("Enter String:");
//Store the input in the string variable
userString = scnr.next();
//Output the four values on a single line
//separated by a space
System.out.println(userInt + " " + userDouble + " " + userChar + " " + userString);
}
}
Sample Output:
Enter integer:
>>12
Enter double:
>>23
Enter char:
>>s
Enter String:
>>asdasd
12 23.0 s asdasd
Explanation:
The code above has been written in Java. It contains comments explaining every part of the code. Please go through the comments.