PDA

View Full Version : Kranar?



Soulpieced
09-17-2003, 10:18 PM
You around, or any of you others know a thing or two about Java?

Solkern
09-17-2003, 10:20 PM
I do what's up?
Well I' good with java webpage designing and that sorta thing if it retains to that i'll help out with what i can

[Edited on 9-18-2003 by Solkern]

GSLeloo
09-17-2003, 10:20 PM
I'm in Advanced Computer Programming - Java Honors! But we haven't started Java yet... doing HTML

Soulpieced
09-17-2003, 10:20 PM
I need this part of main and the method call to get me the first 100 prime numbers (2, 3, 5, 7, etc.) . I'm sure just one or two things needs to be changed, but I've spent so many hours on this my eyes are peeling off.

.

case 2:
System.out.println("Performing 4.13");
int count = 1;
int i = 2;
boolean isPrime = true;

while (count <= 100) {
if (isPrime(i));
if (count % 10 == 0) {
System.out.println(i);
}
else System.out.print(i + " ");
i++;
count++;
}
break;

public static boolean isPrime(int num) {
int i;
for (i = 2; i < (num / 2); i++) {
if (i * (num/i) == num)
return false;
}
return true;
}

Soulpieced
09-17-2003, 10:22 PM
This is the output I'm getting.

.

Performing 4.13
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

imported_Kranar
09-18-2003, 12:32 AM
Of course I'm around.

The proper source code is as follows:



public static boolean isPrime(int num) {
for (int i = 2; i <= (num / 2); i++) {
if (i * (num/i) == num) {
return false;
}
}
return true;
}

System.out.println("Performing 4.13");
int count = 0;
int i = 2;

while(count < 100) {
if (isPrime(i)) {
count++;
if (count % 10 == 0) {
System.out.println(i);
}
else System.out.print(i + " ");
}
i++;
}

imported_Kranar
09-18-2003, 12:34 AM
It will give you this output:



2 3 5 7 11 13 17 19 23 29

31 37 41 43 47 53 59 61 67 71

73 79 83 89 97 101 103 107 109 113

127 131 137 139 149 151 157 163 167 173

179 181 191 193 197 199 211 223 227 229

233 239 241 251 257 263 269 271 277 281

283 293 307 311 313 317 331 337 347 349

353 359 367 373 379 383 389 397 401 409

419 421 431 433 439 443 449 457 461 463

467 479 487 491 499 503 509 521 523 541

imported_Kranar
09-18-2003, 12:36 AM
Also, I don't check this folder THAT often, maybe once a week, so if you have any future questions just post them in Off-Topic.

There were two minor problems with the code you gave me, the first was this line:

if (isPrime(i));

And the second, very slight minor error was:

for (i = 2; i < (num / 2); i++)

Which needed to be changed to:

for (i = 2; i <= (num / 2); i++)

Vesi
09-18-2003, 12:44 AM
Okay, I am way out of my league even looking at this page.

See Spot run? Run Spot run!

Vesi (running after Spot)

P.S. I wished my brain could work that way. (secretly jealous)

imported_Kranar
09-18-2003, 12:49 AM
I feel Soulpieced's pain. Only two minor and ever so slight errors lead to incorrect results.

Lord Deprav
09-18-2003, 09:20 AM
Visual Basics is much more forgiving then HTML but its still a bitch. I am doing calculations right now and its just about killin my mind.

Deprav

Bestatte
09-18-2003, 10:31 AM
Okay - this is Java? Because, if it is, it looks an aweful lot like C++.

Heck, I even understood it, and I never looked at Java before.

And I'm not even very good with C++. Or even VB, though I'm better with VB than anything else, being the Access dweeb that I am.

Back
09-18-2003, 10:54 AM
Its a cool code with those winky smilies in it.

imported_Kranar
09-18-2003, 11:12 AM
All programming is the same. Like you can't be good at one language but suck at another. It's called language independence. VB doesn't count because it honest to God is NOT a programming language.

And also, HTML isn't programming either, it's a browser markup language.

HarmNone
09-18-2003, 04:39 PM
Kranar, that is absolutely frightening! I put it into my computer exactly as you had written it and it created a crocodile that ate my ham sandwich! Evil stuff! Evil!

HarmNone does not do Boolean, especially public Boolean! :D