Forums

RS-Linkify Thread is sticky

Quick find code: 261-262-33-65181208

Indecent Act

Indecent Act

Posts: 7,456 Rune Posts by user Forum Profile RuneMetrics Profile
@Bakey,

Sorry for the delay with your avatar. I've been away all week but I'll get it uploaded tomorrow as soon as I get home.

----------------------------------------------------------------------------------------------

Ty everyone for all the coffee, I'm looking forward to getting home so I can catch up with what's been happening on HLF. Yay only one day to go :)

Hmmm....wow, it sucks not having RS Linkify! It's kind of good to see the forums this way because I forget and consider the forums normal with RS Linkify. Not sure I'll learn or benefit from this but it's a nice reminder of the little things RS Linkify does.
But gee, I look forward to browsing the forums with Linkify again.


Take care all <3

23-Jun-2014 17:52:01

Morgan

Morgan

Posts: 36,054 Sapphire Posts by user Forum Profile RuneMetrics Profile
So I'm pretty proud of my little creation here :P It's extremely simple, but it calculates prime numbers from 0 to whatever value you set the for to go. Of course it lacks intuitiveness and a practical use but... I was bored!

public class Testing {

public static void main(String[] args) {

int div = 0;
boolean primeCheck = false;

for(int i = 1; i <= 100; i++) {
for(int i1 = 1; i1 <= i; i1++) {
if(i % i1 == 0) {
div++;
}

if(i1 == i) {
primeCheck = true;
}
}
if(div == 2 && primeCheck == true) {
System.out.println("Number " + i + " is prime.&quot ;) ;
div = 0;
} else if(div != 2 && primeCheck == true) {
div = 0;
}
}
}
}

23-Jun-2014 20:23:03 - Last edited on 23-Jun-2014 20:33:52 by Morgan

Morgan

Morgan

Posts: 36,054 Sapphire Posts by user Forum Profile RuneMetrics Profile
Yay! Just made it so it supports user input. You may now pick the value that'll be used for the for :D

import java.util.Scanner;

public class PrimesAppInput {

public static void main(String[] args) {

int div = 0;
boolean primeCheck = false;
int Number = 0;


System.out.println("Enter the desired number: &quot ;) ;
Scanner reader = new Scanner(System.in);
Number = reader.nextInt();

for(int i = 1; i <= Number; i++) {
for(int i1 = 1; i1 <= i; i1++) {
if(i % i1 == 0) {
div++;
}

if(i1 == i) {
primeCheck = true;
}
}

if(div == 2 && primeCheck == true) {
System.out.println("Number " + i + " is prime.&quot ;) ;
div = 0;
} else if(div != 2 && primeCheck == true) {
div = 0;
}
}
}
}

Ok I better stop spamming this thread :P

23-Jun-2014 21:18:04

Quick find code: 261-262-33-65181208 Back to Top