Question
I need help with my programming code. Instruction: --- Here's what the output should look like: Prime Number Finder: Enter a positive integer to begin
I need help with my programming code.
Instruction:
---
Here's what the output should look like:
Prime Number Finder: Enter a positive integer to begin the search at: 100 Enter a positive integer to end the search at: 200 The prime numbers from 100 to 200: 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 --- Prime Number Finder: Enter a positive integer to begin the search at: 5555500 Enter a positive integer to end the search at: 5555600 The prime numbers from 5555500 to 5555600: 5555507 5555509 5555527 5555567 5555591 ---
Run the code and do the following calculations with it:
Data Range: From 22000 to 22200 Data Range: From 1 to 50 Data Range: From 123456789 to 123456900
My code so far:
package lab8;
import java.util.Scanner;
/*
* This program determines which numbers are prime from a list of integers using a
* brute force algorithm. */
/
public class Example {
public static void main(String[] args) { String line = "";
int[] data; boolean[] prime; boolean anyPrimes = false; int n = 0; int number = 0;
// Initialize scanner for input.
// String to store string of data // The array for storing the data set // Indicators as to whether the number is prime // Indicator if there was any primes displayed. // The size of the data set // The number to check
Scanner input = new Scanner(System.in);
System.out.println("Prime Number Checker:"); // Prompt the user to enter data and read the entire data set as single string. System.out.println("Enter a list of positive integers separated by spaces: "); line = input.nextLine(); input.close();
// Create scanner to read the string line.
Scanner scanLine = new Scanner(line);
// The first pass through just counts how many numbers there are in line.
while (scanLine.hasNextDouble()) { scanLine.nextInt();
n++; }
scanLine.close();
// Check if any data was entered.
if (n == 0) { System.out.println("No data entered."); return;
}
// Create scanner again to read the numbers into the array.
scanLine = new Scanner(line); prime = new boolean[n]; data = new int[n]; for (int i=0; i
data[i]=scanLine.nextInt(); scanLine.close();
}}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started