-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamazon3com.java
160 lines (125 loc) · 3.38 KB
/
amazon3com.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
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
import java.util.Arrays;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Rosenkrantz
*/
public class amazon3com {
static void checker(String x){
String found="";
String tempval="";
int previ=999;
for(int i=0;i<x.length();i++)
{
for(int j=i+1;j<x.length();j++)
{
if(x.charAt(i)==x.charAt(j))
{ if(previ==999 || x.charAt(previ)==x.charAt(j-1))
{
tempval+=x.charAt(j);
previ=i;
break;
}
}
}
}
if(tempval.length()>found.length())
{
found=tempval;
}
else{
tempval="";
}
System.out.println(found);
}
static void kpoints(int x[][], int k)
{ int cur[]={3,4};
int val[]=new int[k];
int kk=9999;
for(int i=0;i<val.length;i++)
{
val[i]=kk-i;
}
//System.out.println(Arrays.toString(val));
for(int i=0;i<x.length;i++)
{ Arrays.sort(val);
if( ((cur[0]-x[i][0]) * (cur[0]-x[i][0]) + (cur[1]-x[i][1]) * (cur[1]-x[i][1]))< val[k-1] )
{
val[k-1]=((cur[0]-x[i][0]) * (cur[0]-x[i][0]) + (cur[1]-x[i][1]) * (cur[1]-x[i][1]));
}
}
System.out.println(Arrays.toString(val));
}
static int factorial(int x)
{
int fact=1;
while(x>0)
{
fact*=x;
x--;
}
return fact;
}
static double coss(double x)
{ x= x*3.14159/180;
double cosv=0;
boolean sign=true;
for(int i=0;i<20;i+=2)
{
double datum=Math.pow(x,i)/factorial(i);
if(!sign)
cosv+=datum*(-1);
else
cosv+=datum;
sign=!sign;
}
return (cosv);
}
static double sinn(double x)
{ x= x*3.14159/180;
double sinv=0;
boolean sign=true;
for(int i=1;i<22;i+=2)
{
double datum=Math.pow(x,i)/factorial(i);
if(!sign)
sinv+=(-1)*datum;
else
sinv+=datum;
sign=!sign;
}
return (sinv);
}
static void ran()
{ int arr[]={1,2,3,4,5};
for(int i=0;i<5;i++)
{
//System.out.println(val);
int index=(int)(Math.random()*1000)%arr.length;
//System.out.println(index);
System.out.println("Random Value "+arr[index]);
}
}
// static recfibo(int x)
//{
//}
public static void main(String args[])
{/*
String x="abcdabcdxxabcrrbcdgwb";
//int[] xx=new int[4];
int [][] xx={{1,2},{3,4},{5,6},{3,2},{3,3}};
//System.out.println(xx[0][0]);
checker(x);
kpoints(xx,2);*/
// System.out.println(factorial(3));
System.out.println(coss(45));
System.out.println(sinn(45));
System.out.println((2<<1)+" "+(2<<3));
int a;
int b;
ran();
}
}