Java Day 1 - Data Types



Task
Complete the code in the editor below. The variables i, d, and s are already declared and initialized for you. You must:

Declare 3 variables: one of type int, one of type double, and one of type String.
Read 3 lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your 3 variables.
Use the + operator to perform the following operations:
Print the sum of i plus your int variable on a new line.
Print the sum of d plus your double variable to a scale of one decimal place on a new line.
Concatenate s with the string you read as input and print the result on a new line.



  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6. public class Solution {
  7. public static void main(String[] args) {
  8. int i = 4;
  9. double d = 4.0;
  10. String s = "HackerRank ";
  11. Scanner scan = new Scanner(System.in);
  12. /* Declare second integer, double, and String variables. */
  13. int ii = scan.nextInt();
  14. scan.nextLine();
  15. double dd = scan.nextDouble();
  16. scan.nextLine();
  17. String ss = scan.nextLine();
  18. System.out.println(i + ii);
  19. System.out.println(d + dd);
  20. System.out.println(s + ss);
  21. /* Read and save an integer, double, and String to your variables. */
  22. // Note: If you have trouble reading the entire String, please go back and
  23. // review the Tutorial closely.
  24. /* Print the sum of both integer variables on a new line. */
  25. /* Print the sum of the double variables on a new line. */
  26. /*
  27. * Concatenate and print the String variables on a new line; the 's' variable
  28. * above should be printed first.
  29. */
  30. scan.close();
  31. }
  32. }