-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRMIImplementation.java
More file actions
197 lines (185 loc) · 5.44 KB
/
RMIImplementation.java
File metadata and controls
197 lines (185 loc) · 5.44 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.rmi.*;
import java.rmi.server.*;
import java.util.Arrays;
public class RMIImplementation extends UnicastRemoteObject implements RMIInterface {
public RMIImplementation() throws RemoteException{
}
public int Cong2so(int a,int b) throws RemoteException{
return (a+b);
}
//so chinh phuong
public boolean KT_SoChinhPhuong(int n) throws RemoteException {
for (int i = 1; i <= n / 2; i++)
if (i * i == n)
return true;
return false;
}
public int[] kq_SoChinhPhuong(int a[]) throws RemoteException{
int j=0;
int b[]=new int[a.length];
for(int i=0;i<a.length;i++)
if(KT_SoChinhPhuong(a[i])==true)
{
b[j]=a[i];
j++;
}
return b;
}
//Fibonaci
public boolean Is_Perfect_Square(int n) throws RemoteException{
int s=(int) Math.sqrt(n);
return (s*s==n);
}
public boolean KT_Fibonaci(int n) throws RemoteException {
// n is Fibonacci if one of 5*n*n + 4 or 5*n*n - 4 or both
// is a perfect square
if(Is_Perfect_Square(5*n*n + 4) || Is_Perfect_Square(5*n*n - 4))
return true;
else
return false;
}
public int[] kq_Fibonaci(int a[]) throws RemoteException{
int j=0;
int b[]=new int[a.length];
for (int i=0;i<a.length;i++)
if(KT_Fibonaci(a[i])==true)
{
b[j]=a[j];
j++;
}
return b;
}
public int[] kq_GiamDan(int a[]) throws RemoteException{
int j=0,temp=0;
for (int i=0;i<a.length;i++)
{
for(int k=i+1;k<a.length;k++)
if((a[i])>a[k])
{
temp=a[i];
a[i]=a[k];
a[k]=temp;
}
}
return a;
}
public int[] kq_TangDan(int a[]) throws RemoteException{
Arrays.sort(a);
return a;
}
public int kq_Max(int a[]) throws RemoteException
{
int temp=0;
for(int i=0;i<a.length;i++)
{
if(a[i]>temp)
{
temp=a[i];
}
}
return temp;
}
public int kq_Min(int a[]) throws RemoteException
{
int temp=0;
for(int i=0;i<a.length;i++)
{
if(a[i]<temp)
{
temp=a[i];
}
}
return temp;
}
public int kq_CongMang(int a[]) throws RemoteException{
int j=0,sum=0;
for (int i=0;i<a.length;i++)
{
sum+=a[i];
}
return sum;
}
public int kq_TruMang(int a[]) throws RemoteException{
int j=0,sum=0;
for (int i=0;i<a.length;i++)
{
sum-=a[i];
}
return sum;
}
public float kq_TrungBinhMang(int a[]) throws RemoteException{
int j=0,sum=0;
for (int i=0;i<a.length;i++)
{
sum+=a[i];
}
float average =(float)sum/a.length;
return average;
}
public String MaSV_3SoCuoi(String a) throws RemoteException
{
int lengh = a.length();
String b= null;
b= a.substring(lengh-3);
return b;
}
public int KTnamnhuan(int a)throws RemoteException{
if ((a%4==0)&&(a%100!=0)) return 1;
else return 0;
}
public int Songay(int n,int nam)throws RemoteException{
switch(n){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
return 31;
case 4: case 6: case 9: case 11:
return 30;
case 2:
if(KTnamnhuan(nam)==1) return 29;
else return 28;
default:
return 0;
}
}
public String XepLoai(float diem)throws RemoteException{
String XL="";
if(diem <5) XL="HANH KIEM YEU";
if((diem >=5)&&(diem<7)) XL="TRUNG BINH";
if((diem>=7)&&(diem<8)) XL="KHA";
if(diem>=8) XL="GIOI :D";
if((diem>10)||(diem<0)) XL="DIEM KHONG HOP LE";
return XL;
}
public double Tinhgiaithua(int n) throws RemoteException{
if(n==0) return 1;
else return n*Tinhgiaithua(n-1);
}
public int KTChuoiDX(String s) throws RemoteException{
if (s.substring(0, s.length() / 2).equals(new StringBuffer(s.substring(s.length() - (s.length() / 2))).reverse().toString())) {
return 1;
} else {
return 0;
}
}
public String ChuanhoaSpace(String s) throws RemoteException{
s.trim();
return s;
}
public String chuanHoa(String str) throws RemoteException {
str = str.trim();
str = str.replaceAll("\\s+", " ");
return str;
}
public String chuanHoaDanhTuRieng(String str) throws RemoteException {
str = chuanHoa(str);
String temp[] = str.split(" ");
str = ""; // ? ^-^
for (int i = 0; i < temp.length; i++) {
str += String.valueOf(temp[i].charAt(0)).toUpperCase() + temp[i].substring(1);
if (i < temp.length - 1) // ? ^-^
str += " ";
}
return str;
}
}