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];
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)
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 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 the following piece of code Iam confused as to where the InputMismatchException in the catch block is thrown on the first place? Is the InputMismatchException thrown automatically with declaring to throw the exception?
import java.util.*;
public class InputMismatchExceptionDemo { public static void main(String[] args) { Scanner input = new Scanner(System.in); boolean continueInput = true;
Is it a best practice to return from try block or place return statement after try-catch when we intend to return a value from a method(* Catch block is being also used to rethrow the exception)??
Regarding return statements within methods. So I have a method containing try and catch block (as required) and much like when you have an if else statement... I noted you have to return an object for both the try and catch blocks. Now in my case my method should return a List object.
The way I have tried to overcome this:
- I've initialised a List object to null as an attribute of the class I'm working in. - Therefore in the catch block would just simply return the null List object, where as the try block would return the non-empty List (which is what I want). - I then just test to see if the List != null, when the method is invoked... and that is that.
However the method always seems to return null (when it shouldn't).
Modify the program in Assign4 to synchronize access to the instance variable, balance. Save the program as SyncBank.java. Because balance is a double and not an object, it cannot be used as the monitor. Use synchronized methods or synchronized blocks of code as appropriate. Simultaneously test two threads as was done in Assign4. Because the threads can complete too quickly to determine if they are interfering with each other, delay the adding of a deposit by inserting the following code within the synchronized block or method:
It's always good to keep functions smaller and focused on one behavior. So is this safe:
Java Code:
public Unit findBySql(int id){ Unit unit=null; DbConnectionPool dbPool = DbConnectionPool.getInstance(); HashMap<String, String> conditions = new HashMap<String, String>(); conditions.put("id", String.valueOf(id)); String sql = buildSelect("units", "*", conditions);
[Code] ......
As you can see a pass ResultSet to a function which populates the item. But I also make sure that the ResultSet that the passed object is pointing to is closed, so it doesn't leak resources.
I am developing a Client/Server java application, where CSMessage is sent through socket.CSMessage has some data like String type and HashMap<String, String> type.the Client send message:
private ObjectInputStream in; private ObjectOutputStream out; out = new ObjectOutputStream(socket.getOutputStream()); in = new ObjectInputStream(socket.getInputStream());
[code]....
When this happen, the only way to make the system to work is to kill the process and restart it, that's bad!
My current lesson in Java is about ArrayLists and I'm having a tough time to understand this bit of code: This exercise is concerned with the problem of deleting a block of items from an ArrayList.
public static void deleteBlock( ArrayList<String> strings, int n ) { for ( int i = 0; i < n; i++ ) { if ( strings.size() > 0 ) strings.remove( i );
So method invia call the method popolaScompiute, inside popolaScompiute there is an iteraction through some id and for some id can occur an error; what i want is the getting the value of id in the first method invia, using the block try/catch. Is there a way to accomplish this?
public class hello { /** * @param args */ public static void main(String[] args) { int s = new hello().h(); System.out.println(s); } public int h(){ try{ int g = 10/0;
[Code] .....
the output is 7. how the flow is working. i understand that there is a divide by zero exception after which the control goes to catch. what about the return statement in catch . why is it overridden by finally..........
I came across a code where the exceptions can be thrown from catch and finally block too. I never gave a thought on what scenarios that can be required. Some practical examples when/where it can be required to throw the exception from catch and finally blocks.
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package part1; import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; class brick {
I want to use a try catch block, but I am not sure how to fix this problem:
int a;
try{ a = Integer.parseInt(A.getText()); } catch (Exception e){ Output1.setText("Error"); }
//do someting with a here
The purpose of the try-catch is to catch blank input.The problem with this is that underneath the try - catch I get an error saying that the variable might not have been initialized. I know why this happens. I know I could initialize the varaible before the try - catch, but there is no default or null I can set an int as. If I initialized it as 0, the blank input will no longer be catched.how to make this problem disappear?