Program To Pull Prime Numbers Between Two Entered Values
Oct 18, 2014
Program to pull prime numbers between two entered values,
import java.util.Scanner;
public class question6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter lower int:");
Program is to list all prime numbers between two entered numbers.
import java.util.Scanner; public class question6 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter lower int:"); int x = input.nextInt();
I want to find the prime palindrome numbers less that a given number by my program. Here is my code, I am trying to find the method to solve the errors when I compile it. It said variable a might not have been initialized in line 41,62,86.
import java.util.Scanner; public class Lab5{ public static void main (String[] args){ System.out.println("Please input a number"); Scanner Input=new Scanner(System.in); int num = Input.nextInt();
I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.
public class PrimeNumber { Scanner scan = new Scanner(System.in); int userNum; String neg;
I tried to create file and write the output of my program in it in java when i use WriteLong then the file does not contain long value, how I create this file my program is to print prime numbers between 500000 to 10000000
public class primenumber { public static void main(String[] args) { long start = 5000000; long end = 10000000; System.out.println("List of prime numbers between " + start + " and " + end); for (long i = start; i <= end; i++) { if (isPrime(i)) { System.out.println(i);
This program reads off of a text file that I have attached to my post. It is supposed to:
display the total sales for each week the average daily sales for each week the total sales for all of the weeks the average weekly sales the week number that had the highest amount of sales the week number that had the lowest amount of sales
I can get everything but the very last one. In my code you will see that I tried to use a really large number so it would pull out the lowest amount, but it still didn't work: low = 100000000;
SalesData.txt (173bytes) Number of downloads: 29 import javax.swing.JOptionPane; import java.io.*; import java.text.DecimalFormat; import java.util.Scanner;
The assignment is to make a program that prints the number of prime numbers in a range. This is what i have so far. The output is a list of 2s. I created the for loop to cycle through the range of 17-53 and nested a while loop within to test each incident of the for loop to check for divisors starting with 2 until the modulus result is 0 resulting in a false for being a prime number. Then the loop should increment to the next i value. The last part is an if statement that i had intended to add counters to the k variable that would keep track of the number of prime numbers.
boolean isPrime = true; int j = 2; int k = 1; for (int i = 17; i <= 53; i++){ { while (i % j == 0){ isPrime = false;
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println(" Enter the maximum number "); int maxNumber = scanner.nextInt(); int[]numberList = createList (maxNumber);
[code]....
I have a problem with the output. It only get as far as marking the multiples of 2. It does not mark the multiples of 3 and so on.Example output: If the range is from 2 to 15 the output is :2, 3, 0, 5, 0, 7, 0, 9, 0, 11, 0, 13, 0, 15 note: 0 means its marked.As you can see it only marks multiples of 2 but it does not mark multiples of 3 above. I think the problem lies in the for loop inside my main method, because the index does not increment.
The challenge is to weed out all the prime numbers without using any kind of division (%, /). My code doesn't weed out certain numbers, such as many multiples of 5, the number 49, etc, and I am not sure why. Here is my code.
My logic for the for loops was this: Starting with the upper numbers of the ArrayList, find every number that is a multiple of that number and remove it from the ArrayList. Every time you find a multiple, increase the variable multiply, so the program knows what the next multiple to look for.
// program doesn't work yet. import java.util.ArrayList; // import java.util.ListIterator;
public class Sieve2 { public static void main(String[] args) { int upperLimit = 55; ArrayList<Integer> primes = new ArrayList<Integer>();
the prime numbers from 1 to 2500 can be obtained as follows. From a list of the numbers of 1 to 2500,cross out al multiples of 2 (but not 2 itself). Then, find the next number (n, say) that is not crossed out and cross out all multiples of n (but not including n).
Repeat this last step provided that n has not exceeded 50 (the square root of 2500). The numbers remaining in the list (except 1) are prime. Write a program which uses this method to print all primes from 1 to 2500. Store your output in a file called primes.out.
The game doesn't seem to be working but you can win by loading a winning saved game.
Hint: Remember that all numbers have a unique set of Prime Factors.
I have been struggling to solve this. The code is not in error. I am trying to load a winning file but unable to solve.
Here is the java code:
import java.math.BigInteger; import java.util.ArrayList; import java.util.HashSet; import java.util.Random; import java.util.Scanner; import java.util.Set; public class Main { static final int GAME_SIZE = 40; //Disk sizes go from 0->39 // Produce a list of the first N prime numbers
[Code] ....
Results:
C:UsersSal_2>java Main Welcome to Towers of Toast!!! Type 'new' to start a new random puzzle Type 'load' to load a saved puzzle new [0, 2, 3, 4, 5, 6, 8, 10, 14, 19, 20, 25, 26, 28, 35, 38, 39] [7, 9, 11, 13, 15, 21, 22, 23, 27, 31, 32] [1, 12, 16, 17, 18, 24, 29, 30, 33, 34, 36, 37] | | XX | | XXX | | XXXX | | XXXXX | | XXXXXX | X XXXXXXXX XXXXXXX XXXXXXXXXXXX XXXXXXXXXX XXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The game is broken! We saved your game, though. Here are your save game numbers:
C:UsersSal_2>java Main Welcome to Towers of Toast!!! Type 'new' to start a new random puzzle Type 'load' to load a saved puzzle load Enter save number for pole 1: 3 Enter save number for pole 2: 1 Enter save number for pole 3: 11 Exception in thread "main" java.lang.RuntimeException: Not all disks accounted f or at Main.main(Main.java:100)
How to calculate the minimum and the maximum in the same program.
public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int integers; int[] numbers; numbers = new int[10]; int max; int min;
[Code] ....
My result when I input numbers are always the following:
"Numbers in reverse order are: 9, Numbers in reverse order are: 8, Numbers in reverse order are: 7, Numbers in reverse order are: 6 Numbers in reverse order are: 5, Numbers in reverse order are: 4, Numbers in reverse order are: 3, Numbers in reverse order are: 2, Numbers in reverse order are: 1, Numbers in reverse order are: 0."
I have a GUI with a textArea for the user to input numbers, a button which should "listen" for those numbers, and then a textField to display the sum. I have my code working for user input of one number; but I'm at a loss as to what sort of loop I need to create to get it to read each line of input. I wasn't sure whether to put this in the beginner forum or here, because I am definitely a beginner.
I need to write a Java program to perform a mathematical calculation between two numbers entered by the user. User has to choose the mathematical operation and input it and then when the user enters 2 numbers, he gets the answer. When user enters any other character other than *, /, + and - he should be able to exit. Perform calculation between numbers should be until user decided to exit from the program. My code is below, calculation part goes well, but can't get it exit when user enter any other character.. How to fix it?
import java.io.*; public class q11 { public static void main(String[]args)throws IOException { InputStreamReader ISR=new InputStreamReader(System.in); BufferedReader BR=new BufferedReader(ISR); while(true){ System.out.println("Enter.."); System.out.println("* : For multiplication");
I am writing a program that checks if a number is prime or not. Code below.
for(int i = 2; i < P; i++){ if (P % i == 0) { System.out.println(P + " Can also be divided: " + i); return; } } System.out.println("Prime number.");
It works but, if a number is not a prime. I need to print out all the numbers that it can be divided with. For example if a number would be 8: it can also be divided with 1, 2, 4, 8.
a. Write a Java program to input 10 integer numbers into an array named fmax and determine the maximum value entered. Your program should contain only one loop, and the maximum should be determined as array element values are being input. (Hint: Set the maximum equal to the first array element, which should be input before the loop used to input the remaining array values.)
b. Repeat 1a, keeping track of both the maximum element in the array and the index number for the maximum. After displaying the numbers, display these two messages:
The maximum value is: _________ This is element number __________ in the list of numbers
Have your program display the correct values in place of the underlines in the messages.
c. Repeat 1b, but have your program locate the minimum value of the data entered.
I did parts a and b but for part see i just want to know if i did it correctly or not
import java.util.Scanner; public class MinimumValueArray { public static void main(String[] args) { //Variable Declaration Scanner keyboard = new Scanner(System.in); int size = 10;
[Code] ,.....
When I run it i get this The minimum value is 0.0
The element that holds the value is 0 right away. is this right for the minimum or am i supposed to enter values and it will display the minimum value like in parts a and b wit the maximum? will the minimum just always be 0 or ?
So I have to convert strings to double numbers and there can be no exception.
The strings that aren't numbers or do not fit into a set criteria have to be discarded.
When I try to write this I get an exception when a non-numeric is entered and the code stops.
What can I do? Also, am I finding the average of the array correctly?
import java.util.*; public class Grades{ public static void main(String args[]){ int arraycount = 0; final int SIZE = 10; int validArraycount = 0; final int ValidArraySize = 10;
Write a Java program that asks the user to store 10 numbers in an array. You should then print the array in the order entered and then print in reverse order. However, instead of putting all the information in the main, you should use a class called PrintIt. The PrintIt class should have an instance variable that is an array to hold the numbers. You should have a method that will print the array in the order entered. You will also need a method to print in reverse oder. Then create a tester class that asks the user to enter 10 numbers and puts them in an array.
So far I've got this.
public class printIt { int i; int [] numArr = new int [10]; public printIt () { i = -1;
[Code] .....
Output:
Enter a number:
8 34
Forward:
8 34
Reverse:
34 8
end
what i want as an number is being able to print out 10 numbers but this only lets me do two numbers. Why is that so?
I'm quite new in android programming and I've meet some problem in push and pull method. I have created 2 activity in my app 1 of them call Push_activity and Pull activity(Code are shown below). The String that I keyed in PushActivity have to "transfer" to the PullActivity when the button is pressed:
My homework assignment is: Using a do-while statement, write a Java program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should display an appropriate message informing the user that an invalid grade has been entered; a valid grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered. Run the program on your computer and verify the program using appropriate test data.
When I run it, I don't get the correct average. I know that i'm supposed to enter 999 to exit the loop and to display the average, but 999 is being added with the loop. I'm not sure how to make it not do that.
//stephanie import java.util.Scanner; public class gradeAverage { public static void main(String[] args)
I'm unable to get the output for "AverageDriver" to print correctly(5 scores in descending order and average). The output displays the scores the same way they are entered and the average is always zero. The output for the Average program works fine and with the correct output.
import java.util.Scanner; //This class keeps 5 scores entered by the user public class Average { private int[] data; private double mean; public Average()
I'm trying to pull the authors from this Json object but I'm having issues trying to pull the author only, I'm only able to get a huge string which is a valid JSON object i tested it in [URL]
I've been trying to pull data from another class file "Calculations.java" and have it be displayed in a TextField in "DataAnalyzerGUI.java". Here is how the hierarchy is broken down for my assignment: