Divide And Conquer
Oct 28, 2014I believe i need Divide and Conquer method, maybe im wong..
I have to solve this:
x2+s(x)+200·x=N
N is given by the user, also A and B, which is the range of X.
but the range can be up to 1,000,000,000
I believe i need Divide and Conquer method, maybe im wong..
I have to solve this:
x2+s(x)+200·x=N
N is given by the user, also A and B, which is the range of X.
but the range can be up to 1,000,000,000
I was given an algorithm to implement and i did it in java. its some divide and conquer algorithm probably some comparison sort..heres the code i wrote...
import java.util.*;//so as to get the functions for using arrays
public class main
{
public static void main(String[] args)
{
int m[]={10,2,3,4,5,6,7,8,9,1};
int result[]=new int[200];
[Code] ....
the program compiles without errors. but while running i get the following errors:
java.lang.ArrayIndexOutOfBoundsException: 10
at main.abc(main.java:28)
at main.main(main.java:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
here is code :
public final static void main(String[] args){
double d = 10.0 / -0;
if(d == Double.POSITIVE_INFINITY)
System.out.println("Positive infinity");
else
System.out.println("Negative infinity");
}
now ideally this might throw Arithmetic Exception.. but it prints positive infinity ,.. why.. ??
I made a calculator that does the basic operations but I want to be able to divide more than two numbers by repeatedly entering values using an arraylist and I keep getting the indexoutofboundsexception and I don't know why? I understand the reason behind the outofboundsexception but I can't figure out why in this case. Here is a snippet:
public Double division(ArrayList<Double> list){
Double dnum = 0.0;
Double divide = numList.get(0); // Initialize divide to first element in the arraylist
for(int i=0; i < numList.size(); i++){
[Code] ....
public static void main (String [] args) {
int a = (int) 0.25;
int b = (int) 1.25;
int result = a + b;
System.out.println("Result of addition is "+ result);
}
}
Divide an Array in two Parts in such a way so that sum will be equal while we add all the elements of array.
View Replies View RelatedI have to divide a text file into blocks of 128 bits. I think i must use the ByteArrayInputStream and ByteArrayOutputStream classes. is there any website showing how to user these two ByteArrayInputStream and ByteArrayOutputStream classes in detail. or it would be much better if you could show me a portion of the code.
View Replies View RelatedI am using Java 2D API to implement Graph plotting. I am able to transform and scale the origin upright.
Now, I need to divide the x & y axes with frequencies (Ex: On Y-axis: 0 10 20 30 40 etc ..) and then plot points (Ex: [34, 54] etc) accordingly.
Which methods to use or way out to make this implementation?