-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay1-Data-Types
More file actions
53 lines (38 loc) · 2.09 KB
/
Day1-Data-Types
File metadata and controls
53 lines (38 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Problem:
Objective
Today, we're discussing data types. Check out the Tutorial tab for learning materials and an instructional video!
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 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.
Solution:
int i2;
double d2;
String s2 = "";
/* Read and save an integer, double, and String to your variables.*/
i2 = scan.nextInt();
d2 = scan.nextDouble();
String f = scan.nextLine();
s2 = scan.nextLine();
// Note: If you have trouble reading the entire String, please go back and review the Tutorial closely.
/* Print the sum of both integer variables on a new line. */
int i3 = i+i2;
double d3 = d+d2;
String s3 = s+s2;
System.out.println(i3);
/* Print the sum of the double variables on a new line. */
System.out.println(d3);
/* Concatenate and print the String variables on a new line;
the 's' variable above should be printed first. */
System.out.println(s3);
/* Declare second integer, double, and String variables. */
/* Read and save an integer, double, and String to your variables.*/
// Note: If you have trouble reading the entire String, please go back and review the Tutorial closely.
/* Print the sum of both integer variables on a new line. */
/* Print the sum of the double variables on a new line. */
/* Concatenate and print the String variables on a new line;
the 's' variable above should be printed first. */