Question: Drawl a UML class diagram for this program //prime.java /** * */ package com.test; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import
Drawl a UML class diagram for this program
//prime.java
/**
*
*/
package com.test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* @author surya
*
*/
public class Prime
{
// Driver Program to test above function
public static void main(String args[]) throws FileNotFoundException
{
Scanner sc = new Scanner(System.in);
System.out.print("Please enter a upper bound number: ");
int N = sc.nextInt();
// Creating a File object that represents the disk file.
PrintStream o = new PrintStream(new File("C:\\Users\\surya\\eclipse-workspace\\Chegg\\src\\com\\test\\prime.txt"));
// Store current System.out before assigning a new value
PrintStream console = System.out;
// Assign o to output stream
System.setOut(o);
System.out.println("Following are the prime numbers ");
System.out.println("smaller than or equal to " + N);
Prime g = new Prime();
boolean prime[] = new boolean[N+1];
for(int i=0;i prime[i] = true; for(int p = 2; p*p <=N; p++) { // If prime[p] is not changed, then it is a prime if(prime[p] == true) { // Update all multiples of p for(int i = p*2; i <= N; i += p) prime[i] = false; } } // Print all prime numbers for(int i = 2; i <= N; i++) { if(prime[i] == true) System.out.println(i + " "); } } } //output
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
