-
Notifications
You must be signed in to change notification settings - Fork 2
/
5.1 Interchange two Value.java
49 lines (35 loc) · 1.12 KB
/
5.1 Interchange two Value.java
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
/*
Write a java program that performs the following steps. a. Declare two int variables named x and y. b. Assign input taken from user to x. c. Assign twice the value of x to y. d. Interchange the value of x and y. e. Print the values of both variables on screen.
Input Format
a positive integer value
Constraints
a positive integer value
Output Format
display 2 integers as per instructions on the screen
Sample Input 0
5
Sample Output 0
10 5
Sample Input 1
10
Sample Output 1
20 10
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
//Createing Input Object of Scanner class as sc
Scanner sc = new Scanner(System.in);
// declaring variables x and y of in type and taking input for x;
int x = sc.nextInt();
int y = 2*x;//since y is twice of x
//interchanging value of x and y
int temp = x;
x = y;
y = temp;
//printing the result
System.out.print(x+" "+y);
}
}