-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice1.java
More file actions
77 lines (65 loc) · 1.77 KB
/
Copy pathpractice1.java
File metadata and controls
77 lines (65 loc) · 1.77 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package college_class_practice;
import java.util.Scanner;
public class practice1{
public static void main(String[] args) {
// 6. Swap two numbers using a temporary variable
System.out.println("PRACTICE SESSION");
// swap_using_temp();
// swap_without_temp();
// even_odd();
calculator();
}
public static void calculator(){
Scanner input = new Scanner(System.in);
System.out.println("enter a and b :");
int a = input.nextInt();
int b = input.nextInt();
System.out.println("To solve : 1.(+)add \n 2.(-)sub ");
// int c = input.nextInt();
char c = input.next().charAt(0);
switch(c){
case '+':
System.out.println("The sum is : ");
System.out.print(a+b);
break;
case '-':
System.out.print("The difference is : ");
System.out.print(a-b);
break;
default:
System.out.println("INVALID INPUT");
}
input.close();
}
public static void swap_using_temp() {
int a = 12, b = 78;
int temp ;
temp =a ;
a = b;
b = temp ;
System.out.println("a is ");
System.out.println(a);
System.out.println("b is ");
System.out.println(b);
}
public static void even_odd (){
int a = 3;
if(a%2 == 0){
System.out.print(a);
System.out.println(" is even");
}else{
System.out.print(a);
System.out.println(" is odd");
}
}
public static void swap_without_temp(){
int a = 12, b = 78;
a = a + b;
b= a - b;
a = a - b ;
System.out.println("a is ");
System.out.println(a);
System.out.println("b is ");
System.out.println(b);
}
}