September 2010
M T W T F S S
« Dec    
 12345
6789101112
13141516171819
20212223242526
27282930  

Categories

Project Euler Problem 61 in Java

 Show Problem 61
This gave me a headache. I was about to give up when I recalled that recursion is a very powerful tool and is very suitable for this question. The code does not look so pretty or concise but it is really powerful. I think you can figure out easily what I tried to [...]

Project Euler Problem 72 in Java

Finally, I have found a very efficient answer for Problem 72. It runs under 1 seconds. It uses prime sieve of Eratosthenes.

Here is the code in Java

?View Code JAVA1
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
import java.util.Arrays;
 
public class Problem72 {
 
public static void main(String args[])
{
int n=1000000;
int[] phi = new int[n+1];
for (int i=0; i<n+1; i++)
phi[i]=i;
 
boolean[] p = new boolean[n+1];
Arrays.fill(p, true);
p[0]=false;
p[1]=false;
for (int i=2; i<=n; i++)
{
 
if [...]

Project Euler Problem 102 in Java

Show Problem 102
First of all we need a method to check whether a point is in the triangle or not. This site has some useful info regarding this issue. Actually, it is for three dimension but two dimensions is applicable if we set the third dimension to zero always. All we need to code is [...]

Project Euler Problem 62 in Java

Show Problem 62

For this one I used a map. I calculated the cubes for integers till 10000. Then I sorted every cube. Using a hashmap I calculated the frequency of each sort. If the freq is 5, that gives us the combination. Using another hashmap I associated the integer before cube calculation with the combination. [...]

Project Euler Problem 112 in Java

Show Problem 112

This one is very easy if you know the trick. Here is the trick. If you sort a number ascendingly and if it is still equals the same number then it is an increasing one. If you sort it descendingly and is still the same number it is a decreasing one. If neither [...]

Project Euler Problem 85 in Java

This problem was fun. You have to come up with a way to count the rectangles in a rectangular grid. I used a four nested loop to count the rectangles. First two loops specify the grid size. Then the other two nested loops do the actual work. I assumed that the answer would be in [...]

Project Euler Problem 74 in Java

When I first solved this problem I used BigIntegers. It took about 30 minutes to find the answer. The reason for that is I used BigIntegers and a binarysort in a loop. In fact the numbers used do not exceed integer limit so there is no need to use BigIntegers. So I present the more [...]

Project Euler Problem 65 in Java

Hi everyone. It has been a while. In meantime I have discovered how fun it was to solve projecteuler.net problems. From now on I decided to publish my answers here. Actually, I was publishing them in the forum section of javaist. However, there has been some spamming there so I decided to carry my answers [...]

A Simple Calculator Applet in Java

This program illustrates some GUI usage through buttons, panels and text field. It makes use of layout managers and event handlers. Feel free to investigate the code and even make the applet a better one.

?View Code JAVA1
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
//Calculator.java
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
public class Calculator extends JApplet
{
private JPanel [...]

Java Programming Language

Java is a programming language developed by Sun Microsystems. It derives much of its syntax from C and C++. Java applications run on any Java Virtual Machine regardless of computer architecture. Java applets are popular web applications.  Here is how Hello World implemented in Java.

?View Code JAVA1
2
3
4
5
6
// HelloWorld.java
public class HelloWorld {
public [...]