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>();
I want to make project about java communication with hardware (wiz110sr) via LAN (Rj45). And for example, my hardware have ip address 198.168.0.1 ; port: 1202, connected with my PC(via lan/Rj45). I want show the output (such as numbers and letters) from my hardware in console netbeans.
When I running my code, appear :
" Exception in thread "Thread-0" java.lang.RuntimeException: Uncompilable source code at mypkg.startListenForTCP$1.run(startListenForTCP.ja va:48) at java.lang.Thread.run(Thread.java:745) BUILD SUCCESSFUL (total time: 1 second) "
I'm doing project in area of "Cryptography and Network security". I'm having a file with binary Unicode (mean file contain Unicode value of corresponding data (text file)), want to divide that as blocks with the size of 144bits.
I am having problems with my code I have added the multiplication and division but they will not display also how can I correct any error when dividing by zero?
import java.awt.*; import java.awt.event.*; public class calculator2 extends java.applet.Applet implements ActionListener { TextField txtTotal = new TextField(""); Button button[] = new Button[10];
I want to make app in netbeans. When i write numbers in JTextField like 1,2,3,4,5,6... it should show me in JOptionPane information window result of ODD numbers.
class A { List<StringBuilder> list; public void output(List<StringBuilder> objectToOutput){ try(BufferedWriter bw = new BufferedWriter(new FileWriter("temp.txt"))){ for(StringBuilder row:objectToOutput) bw.write(row.toString()); }catch(IOException e){}
[code]....
Why don't the a's show up on the console? I put them in as part of the debugging process and now I don't understand why they don't show up in both places.
Here is the Butterfly sub division technique which refines the mesh of a STL file.I have to prepare a java code based on this technique, give the step by step procedure or algorithm for this.(files attached)
I was trying to execute the following program and the multiplication worked but the division didn't work.
import java.util.Scanner; public class BodyMassIndex { public static void main(String[] args) { // Prompt the user for weight and height // Create a scanner Scanner input = new Scanner (System.in); System.out.println("Please enter your weight in pounds"); int weight = input.nextInt(); System.out.println("Please enter your height in inches"); int height = input.nextInt (); double BMI = weight * (0.45359237)/ (height * 0.0254)*(height * 0.0254); // the weight * (0.45359237) executed but it wasn't divided by (height * 0.0254)*(height * 0.0254) System.out.println ("Your BMI is "+BMI);
Prompt for the project is "Write a program that will ask the user for a number of seconds and output the equivalent period of time in days, hours, minutes, and seconds.The program should:
-Use modulo division to calculate the number of days, hours, and minutes. -Use compound operators when making assignments. -Proper formatting and use of comments -Symbolic constants defined as the number of seconds in a minute, hour, and day.
For example: final int sec_in_min = 60;"
public class Mod1 { public static void main (String[] args) { int sec, min, hr, day; final int SEC_IN_MIN = 60; final int SEC_IN_HR = 60 * 60; final int SEC_IN_DAY = 60 * 60 * 24;
In my application I need to print timezone abbreviation based on location. But fot Australia it is showing EST, even though my time zone data file version is tzdata2014i. I read that from version tzdata2014f, java supports AEST/AEDT but I don't see this in tzdata2014i.
How do i make the 'date' column show only the date and 'timeIn' and 'timeOut' column only show the time. In my database table my 'date' column is a date type and 'timeIn' and 'timeOut' column is time.
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."
package com.arraydemo; import java.util.TimeZone; import java.util.concurrent.TimeUnit; public class ArrayStructures { public long[] theArray; public int arraySize; public ArrayStructures(int size)
So I was making a Java Calculator that only adds. The problem is that the numbers are not adding. I think it is because whatever has been clicked is not being saved to be added.
I am trying to do this assignment but I can't get the needed output. Create a program that asks the user how many floating point numbers he wants to give. After this the program asks the numbers, stores them in an array and prints the contents of the array in reverse order.
Program is written to a class called ReverseNumbers.
Example output
How many floating point numbers do you want to type: 5 Type in 1. number: 5,4 Type in 2. number: 6 Type in 3. number: 7,2 Type in 4. number: -5 Type in 5. number: 2
Given numbers in reverse order: 2.0 -5.0 7.2 6.0 5.4
My code:
import java.util.Scanner; public class apples { public static void main(String[] args) { Scanner reader = new Scanner(System.in); double[] numbers; System.out.print("How many floating point numbers do you want to type: ");
I need a regular expression in java for phone number which that does not allow any character special character only numbers should be allowed.. My sample program is
import java.util.regex.Matcher; import java.util.regex.Pattern; public class c { public String removeOrReplacePhoneNumber(String input) { if (null == input) return input;
in Operator/Literals, it says "There is no literal representation for binary numbers in C, C++, or Java." seems "0b11001" could reprensent binary numbers?
I am working on an assignment but I am not getting any out put and I couldn't fix it?The class HighLow below asks for three integers and prints the highest and lowest of them on screen. Your task is to write the missing methods high and low, which receives the integers user inputs as parameters and return the highest and lowest integers respectively.
import java.util.Scanner; public class HighLow { public static void main(String[] args) { int number1, number 2, number 3, high, low; Scanner reader = new Scanner(System.in);