CurvedSpace Forums: Prime Thingy - CurvedSpace Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • {lang:pm_locked} This topic is locked

Prime Thingy

#1 {lang:macro__useroffline}   Neraphym {lang:icon}

  • Do not want!
  • Icon
  • {lang:view_blog}
  • Group: Super Moderator
  • Posts: 10,332
  • Joined: 29-October 03

Posted 17 May 2005 - 11:42 PM

QUOTE
// randumbness47
// Program to find the median and mean values of all prime numbers from 1 to 10,000

public class Prime
{
public static void main(String[]args)
{
  double median = 0.00;
  double average = 0.00;

  int total = 0;
  int counter = 0;
  int test = 0;
  int divisible = 0;
  int even = 0;

  int half = 0;
  int halfcounter = 0;
  int halfvalue = 0;

  int meda = 0;
  int medb = 0;

  for (int a = 2; a < 10001; a++)
  {
  for(int b = 2; b < a; b++)
  {
    test = a % b;

    if(test == 0)
    divisible = 1;
  }

  if(divisible = 0)
  {
    total = total + a;
    counter = counter + 1;
  }
  }

  average = total / counter;
  even = counter % 2;
  divisible = 0;

  if(even == 1)
  {
  half = counter / 2;

  for (int c = 2; halfcounter < half; a++)
  {
    for(int d = 2; d < c; d++)
    {
    test = c % d;

    if(test == 0)
      divisible = 1;
    }

    if(divisible = 0)
    halfcounter = halfcounter + 1;
  }

  median = c;

  else
  {
  half = counter / 2;

  for (int c = 2; halfcounter <= half; a++)
  {
    for(int d = 2; d < c; d++)
    {
    test = c % d;

    if(test == 0)
      divisible = 1;
    }

    if(divisible = 0)
    {
    halfcounter = halfcounter + 1;

    if(halfcounter == half)
      meda = c;
    }
  } 

  medb = c;

  median = (meda + medb) / 2;
  }

  System.out.println("The Median is: " + median);
  System.out.println("The Average is: " + average);
}
}

Neraphym Archaeon
Posted Image
GWAMM
0

Page 1 of 1
  • You cannot start a new topic
  • {lang:pm_locked} This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users