Ok so I have an assignment which is the following:
There are 25 primes between 2 and 100, and there are 1229 primes between 2 and 10,000. Write a program for which the user inputs an integer N > 2; the program will then display all prime numbers between 2 and N (inclusive), as well as the number of primes between 2 and N. (Your program must actually do the computation to determine if each number is prime, and keep a count of all primes found.)
The output of the program should specify which numbers are the primes between 2 and N, and which number is the number of primes between 2 and N. (In other words, use descriptive text with the output, and it would be a good idea to output the number of primes in a complete sentence!)
Use standard input and standard output for input and output. Your program must prompt the user for the input N. You may assume that the user will input an integer, but not necessarily an integer greater than 2. (In other words, your program must check that the integer input by the user is greater than 2.)
This is what I have so far, I know the format isn't perfect but hey it kinda works. I just can't figure out make a formula/equation for it to work (I switched proffs so i'm really confused)
Code:
package a1;
/**
* <p>Title: Assignment 1</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: UWRF</p>
* @author Eric Merker
* @version 1.0
*/
import java.io.*;
public class Assignment1 {
public Assignment1() {
}
// add throws IOException so an error doesn't occur
public static void main(String[] args) throws IOException {
String userInput;
int N;
BufferedReader br;
br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("What number would you like to enter? ");
userInput = br.readLine();
N = Integer.parseInt(userInput);
//System.out.println("Well, my favorite number is " + userNum + "!");
switch (N) {
case 1: System.out.println("Not a valid prime number");
break;
}
System.out.println("All the primes up to this number are");
//for (userNum = 0; userNum < 400; userNum++);
}
}