Follow exactly all the instructions provided below:
Do not deviate from the instructions provided below or add any unnecessary code to program.
Pay close attention to the directions! Make absolutely certain that you are doing exactly what the assignment asks you to do without any more code required.
Keep the program's code as simple as possible and begineer friendly level with no advanced level Java concepts/skills.
PROGRAM:
import java.util.InputMismatchException;
import java.util.Scanner;
public class PrintPrimes {
public static void main(String[] args) {
//scanner object to read user
data
Scanner input=new
Scanner(System.in);
//variables to store
int number; //variable to store the
number
String repeat=""; //variable to
store whether user's wants to run the program or not
int numOfPrimes=0; //variable to
hold the count of primes
//loop that repeats until user
terminates the program
do
{
//for each
execution set numOfPrimes to 0
numOfPrimes=0;
//read the
number until which user wants to print primes
System.out.print("\nEnter a number: ");
//to check if
user input is valid or not place it in a try catch block
try
{
//read the integer
number=input.nextInt();
System.out.print("\nPrime Numbers upto "+ number
+ " are: \n");
//run a loop from 2 until the specified number
is reached
for(int i=2; i < number; i++)
{
//declare a boolean variable
that tells whether the number is prime or not
boolean isPrime = true;
//run a loop from 2 to
i
for(int j=2; j < i ;
j++)
{
//check if
i is divisible by any other number
if(i % j
== 0)
{
//if divisible set is Prime to false and go to
next number
isPrime = false;
break;
}
}
// print the number if its
prime
if(isPrime)
{
System.out.print(i+" ");
numOfPrimes++; //increment the count of primes
//if
number of primes is divisible by 10 the break the line
if(numOfPrimes%10==0)
System.out.println();
}
}
}
//catch the
exception if user entered invalid input
catch(InputMismatchException exception)
{
//if not a valid
integer print error
System.out.println("Invalid input. Try again...");
}
//ask if user
wants to repeat the execution
System.out.print("\n\nDo you want to run the program again
(yes/no)? ");
input.nextLine();
//read the users
choice
repeat=input.nextLine();
}while(repeat.toLowerCase().equals("yes")); //repeat the execution
as long as user types yes
System.out.print("\nProgram
terminated..");
}
}
OUTPUT:
Follow exactly all the instructions provided below: Do not deviate from the instructions provided below or...
Write a program which: - prompts the user for 2 numerical inputs - stores their two inputs in variables as floats - Use a while in loop to ask a user for a valid operation: (if the user's input operation isn't one of those listed above, instead print a message telling them so, and continue asking for the valid operation) - prompts the user for an arithmetic operation ( + - * / %) - stores the user's input as...
Programming Assignment #2 EE 2372 MAKE SURE TO FOLLOW INSTRUCTIONS CAREFULLY, IF YOU HAVE ANY DOUBTS PLEASE EMAIL ME! This programming assignment will just be a small extension to programming assignment 1. In the first assignment each of the functions could only take a predefined number of inputs. This time the objective is to be able to complete these functions with any amount of inputs. The user will pass arguments through the command line (this means you will have to...
I need a C++ program like this please! and please follow all instructions! Thanks so much! A menu-driven program with 3 choices: Names Rearranger, Number Validator, or Exit Menu Option 1: Name Rearranger: 1. Input ONE STRING from the user containing first name, middle name, and last name. ie, "John Allen Smith". USE THE GETLINE function. (Not cin) 2. Loop through the string and validate for a-z or A-Z or . If the name has any other characters, then ask...
Problem: Create a program that will ask scientist in tracking the resistances of products from various batches. The resistances of good resistors should be between 3 and 3.5 inclusive. Your program will need to track the number of resistances that are too high (>3.5 ohms), the number of resistances that are too low (<3.0ohms) and calculate the average of the resistances that fall in the proper range (>=3 and <= 3.5). Your program should prompt the user to enter name...
Add JavaScript code in the “find_primeV2.js” to allow users to enter a number, and then based on the number of user enters, to find out how many prime numbers there are up to and including the user inputted number and then display them on the web page. The following are the detailed steps to complete this assignment: Step 1. [30 points] In “find_primeV2.js”, complete isPrime() function by (1) Adding one parameter in function header. That parameter is used to accept...
// Finish the following program which adds up all integers from 0 to// the user's given number inclusively using a While Loop. The total should be// assigned to the variable 'total'.#includeusing namespace std;int main() {int number;int total = 0;int counter = 0; //initialize the variable// user enters a numbercout << "Enter a positive integer to find the summation of ";cout << "all numbers from 0 to the given number up to 100." << endl;cin >> number;// check for invalid user...
Please write the following code in C++ for Data
Structures class. Please follow all the instructions in the picture
below. Please write the program with zero warnings.
Description: Please write a short program, randomStream, that asks for the name of a file and a number, and produces a files satisfying the following conditions: The file name is the name given by the user (exactly--no added suffixes please) The number of lines in the file is exactly the same as the...
Use PYTHON3 to create a program that asks the user for their name, and then prints their initials. You must create a function called getInitials() that takes the name string and prints out the initials. It must be case insensitive and the initials must be printed in upper case. The program must contain a main() and a function called getInitials(), implemented as described in the function header comment given below. (You should include this function header comment in your own...
The Sieve of Eratosthenes is a simple, ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking as composite lie., not prime) the multiples of each prime, starting with the multiples of 2 The sieve of Eratosthenes can be expressed in pseudocode, as follows: Input: an integer n Let A be an array of 8oo1ean values, indexed by integers 2 to n, initially all set to true. for t - 2, 3,...
Assignment Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). For non-prime numbers, output a list of all divisors of the number. Format your...