-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment_26.java
More file actions
149 lines (121 loc) · 3.56 KB
/
Assignment_26.java
File metadata and controls
149 lines (121 loc) · 3.56 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import java.util.Scanner;
/*WAP to Accept a no from the user and perform the following task
1:Logical Operator
2: Arithmetic Operation
3: Reverse of the No
4: swapping of two no with third variable
5:Swapping without third variable
6:Accept the value find out the factorial and pass the value of factorial to another function 7
7:Find out the sm of digit
*/
public class Assignment_26
{
int a,b,c;
Scanner sc=new Scanner(System.in);
public static void main(String[] args)
{
Scanner ob=new Scanner(System.in);
Assignment_26 ass=new Assignment_26();
ass.accept_Num();
ass.logical_Operator();
ass.Arithmetic_Operation();
ass.swap_Using_temp();
ass.Swap();
int num;
System.out.println("Enter number");
num=ob.nextInt();
System.out.println("factorial is = "+ ass.Factorial(num));
int fact=ass.Factorial(num);
System.out.println("Sum of Digit is ="+ass.SOD(fact));
}
public void accept_Num()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number");
a=sc.nextInt();
System.out.println("Enter number");
b=sc.nextInt();
System.out.println("Enter number");
c=sc.nextInt();
}
public void logical_Operator()
{
System.out.println("Logical And (&&) "); //if both condition is true then and only then loop will executed
if(a>b && a>c)
{
System.out.println(a+" is greater ");
}
else if(b>c)
{
System.out.println(b+" is greater ");
}
else
System.out.println(c+" is greater ");
System.out.println("Logical or (||) ");//if any one of them condition is true then loop will executed
if(a>b || a>c || b>a || c>b)
{
System.out.println("if condition is true add a b and c = "+(a+b+c));
}
System.out.println("NOT Operator(!)"); // ! operator
System.out.println(!(a == b));
System.out.println(!(a > b));
System.out.println(!(a < b));
}
public void Arithmetic_Operation()
{
System.out.println("Addition of "+a+" + "+b+ " = "+(a+b));
System.out.println("Subtraction of "+a+" - "+b+ " = "+(a-b));
System.out.println("Mulptication of "+a+" * "+b+ " = "+(a*b));
System.out.println("Division of "+a+" / "+b+ " = "+(a/b));
System.out.println("Modules of "+a+" % "+b+ " = "+(a%b));
}
public int reverse()
{
int num= a+b+c,r,rev=1; // for multiplication operation we initialize 1
if(num<=0)
{
System.out.println(" number = "+num);
r=num%10; //remainder
num=num/10;
rev=rev*10+r; // reverse
}
return rev;
}
public void swap_Using_temp()
{
System.out.println("Before Swapping a = "+a+" b= "+b);
c=a;
a=b;
b=c;
System.out.println("After Swapping a = "+a+" b= "+b);
}
public void Swap()
{
System.out.println("Before Swapping a = "+a+" b= "+b); //a=10 b=20
a=a+b; // we take addition of no for getting numbers // a= 10+20=30
b=a-b; //b=30-20=10
a=a-b; //a=30-10=20
System.out.println("After Swapping a = "+a+" b= "+b);
}
public int Factorial(int num)
{
int f=1;
while(num!=0)
{
f=f*num; // f=1*6=6 f=6*5=30 f30*4 120*2 240*1 240
num--;
}
return f;
}
public int SOD(int num)
{
int sum=0,d;
while(num!=0) //we take while because we want stop this loop when number is not equal to 0
{
d=num%10;
sum=sum+d;
num=num/10;
}
return sum;
}
}