java,arrays,enums,polynomials , Transferring code from notepad ++ to command prompt

Transferring code from notepad ++ to command prompt


Tag: java,arrays,enums,polynomials

I'm relatively new to java, so I wouldn't be surprised if I'm missing something obvious here. Anyways, I made a code that finds the roots of a polynomial using the Bisection method. I thought the program was all well and dandy until I pasted it from notepad++ to command prompt, where I ended up getting a bunch of "class, interface, or enum expected" errors after compiling it using javac. Everything seems fine in the code itself, so I've deduced that I've made one of the following two errors: either something wrong occurred while I was copying and pasting into command prompt, or I actually did create an error in my code that I didn't catch. Could someone tell me just what I did wrong? It may be a minor fix, but I just don't know how to change it to get my code to work. Here's the code:

import java.util.*;

class Roots {

  public static int degree;
  public static double[] coArrayC;
  public static double[] coArrayD;
  public static int coeffVal;

  public static void main( String[] args ){
        double resolution = 0.01;
        double tolerance = 0.0000001;
        double threshold = 0.001;

        double rightEndPt;
        double leftEndPt;
        int polyRootPointer = 0;
        int diffRootPointer = 0;

        boolean rootAns = false;

        Scanner sc = new Scanner(;


        System.out.print("Enter the degree: "); //prompts user to enter the correct degree of the polynomial
        degree = sc.nextInt();

        coeffVal = degree + 1; //the coefficient is one more than the number of degrees
        System.out.print("Enter " + coeffVal + " coefficients: "); //adds in the value of the polynomial coefficient in to the line that prompts the user to specify which coefficients are in the function
        double[] coefficients = new double[coeffVal]; //initialization of array, a bunch of doubles that represent the coefficients of the user's polynomial
        coArrayC = new double[coeffVal]; //naming the array

        double[] rootArray = new double[degree];//another array for the degrees of the polynomial

        coArrayD = new double[coeffVal]; //and assigning it a name

        for(int i = 0; i < coeffVal; i++) {
              coefficients[i] = sc.nextDouble();
        System.out.print("Enter the right and left endpoints, in that order: "); //prompts user to enter the interval limits
        rightEndPt = sc.nextDouble();
        leftEndPt = sc.nextDouble();

        diff(coefficients); //calculates coefficients of derivative polynomial

        for (double i = leftEndPt; i < rightEndPt-resolution; i = i + resolution){ //
              if (isPositive(coArrayD, i) != isPositive(coArrayD, i+resolution) || isPositive(coArrayD, i) == 0) {
                    rootArrayDeriv[diffRootPointer] = findRoot(coArrayD, i, i+resolution, tolerance);

        for (int i = 0; i < rootArrayDeriv.length; i++) {
              double tempValue;
              tempValue = poly(coefficients, rootArrayDeriv[i]);
              tempValue = Math.abs(tempValue);
              if (tempValue < threshold) {
                    rootArray[polyRootPointer] = rootArrayDeriv[i];
                    rootAns = true;

        for (double i = leftEndPt; i < rightEndPt-resolution; i = i + resolution){
              if (isPositive(coefficients, i) != isPositive(coefficients, i+resolution) || isPositive(coefficients, i) == 0) {
                    rootArray[polyRootPointer] = findRoot(coefficients, i, i+resolution, tolerance);
                    rootAns = true;

        //Arrays.sort(rootArray); //sorts array from lowest to highest

        if (rootAns == true) {
            System.out.println("Sorry - no roots were found in the specified interval.");
        } else {
            for (int i = 0; i < rootArray.length; i++) {
                if (rootArray[i] != 0.0) {
                    System.out.printf("Root found at %.5f\n :" Arrays.sort(rootArray[i])); //if roots are found, list them as an output, with five decimal places of accuracy

  static double poly(double[] C, double x){
        double polySum = 0;
        coArrayC[0] = C[0];
        for (int i = 1; i < coArrayC.length; i++){
              coArrayC[i] = C[i]*(Math.pow(x, i)); //multiplies each coefficient by the designated power of X
        for (int i = 0; i < coArrayC.length; i++){
              polySum = polySum + coArrayC[i]; //accumulates the sum of of all the terms, after the coeff. were multiplied to their respective powers.


  static double[] diff(double[] C){ 
        for (int i = 0; i < degree; i++){
              coArrayD[i] = (i+1)*C[i+1]; //newly allocated array D containing coeff. of the polynomial that is the derivative of the polynomial with coeff. array C.

  static double findRoot(double[] C, double a, double b, double tolerance){ //using bisection method; similar to in cmps webpage.
        double root = 0.0 , residual;
        while ( Math.abs(b - a) > tolerance ) { 
              root = (a + b) / 2.0;
              residual = poly(C, root);
              if (poly(C, a) < 0 && poly(C, b) < 0) { 
                    if (residual > 0)
                          b = root;
                          a = root;                       
              } else if (poly(C, a) > 0 && poly(C, b) > 0) { 
                    if (residual > 0)
                          a = root;  //replace left endpoint
                          b = root; //replace right endpoint

  static int isPositive(double[] C, double a){
        double endpointTempA;
        endpointTempA = poly(C, a);
        if (endpointTempA < 0) {
        } else if (endpointTempA > 0) {
        } else {


You have two } too many here:

    if (rootAns == true) {
        System.out.println("Sorry - no roots were found in the specified interval.");
    } else {

If you indent your code properly, it's easier to see these kinds of errors. Remove the two } that don't belong there:

    if (rootAns == true) {
        System.out.println("Sorry - no roots were found in the specified interval.");
    } else {

There's also a missing , here, and you shouldn't pass a single double to Arrays.sort, but the whole array

System.out.printf("Root found at %.5f\n :"Arrays.sort(rootArray[i]));

Should be:

System.out.printf("Root found at %.5f\n :", Arrays.sort(rootArray));

And a missing }.

Instead of writing a whole program at once and then trying to compile it, write it little by little, and compile it each time you have for example a complete method. That way you avoid getting a mountain of little errors that confuse you.


Reading and modifying the text from the text file in Java

I am have a project that need to modify some text in the text file. Like BB,BO,BR,BZ,CL,VE-BR I need make it become BB,BO,BZ,CL,VE. and HU, LT, LV, UA, PT-PT/AR become HU, LT, LV, UA,/AR. I have tried to type some code, however the code fail to loop and also,in this...

BitmapFont class does not have getBound(String) method

Previously I used getBound method for BitmapFont class in libgdx, but now, I am unable to use it. I cannot find the changes in latest version. Any help is appreciated. Thank you...

how to call Java method which returns any List from R Language? [on hold]

How to call java method which returns list from R Language.

Can I install 2 or more Android SDK when using Eclipse

I am new to android developments. I am setting up my android development environment using Eclipse. I have a test smart phone with Android version 4.2.2. The automatic installation installed the latest Android SDK version, which is 5.1.1. My questions are: 1. Do I have to install the SDK version...

array and function php

I'm just a beginner in PHP coding. I've been reading through a tutorial, but having some trouble with basic PHP concepts. If you could help me, I'd be much obliged. I'm having trouble understanding why the following code doesn't work. <?php function sum($x, $y) { $z = $x + $y;...

viewResolver with more folders inside of WEB-INF/jsp is not working in spring

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <!-- avoid '???' --> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp"/> </bean> if i create other subfolders under jsp , for instance /WEB-INF/jsp/reports , /WEB-INF/jsp/insertions how should i configure now the viewResolver to can resolve these new sub folders??...

SOAP Client, Following an example

I need to consume a SOAP Server named "Mouser" for my company. However I have a problem when I try to send a message. The documentation of my request is : POST /service/searchapi.asmx HTTP/1.1 Host: Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap12=""> <soap12:Header> <MouserHeader...

Finding embeded xpaths in a String

I have a string where I have the user should be able to specify xpaths that will be evaluated at runtime. I was thinking about having a the following way to specify it. String = "Hi my name is (/message/user) how can i help you with (/message/message) "; How can...

Java Scanner not reading newLine after wrong input in datatype verification while loop

I've looked at similar questions and tried to follow the answers that solved the issues that others have had but putting the or sc.nextLine() after the while loop causes it to go into an infinite loop. The problem is if a user enters incorrect input (nothing or a number)...

PropertyNotFoundException in jsp

Am getting this error in my application javax.el.PropertyNotFoundException: Property 'survey_id' not found on type com.moh.forms.MOH731 javax.el.BeanELResolver$BeanProperties.get( javax.el.BeanELResolver$BeanProperties.access$400( javax.el.BeanELResolver.getValue( This is my @Id @GeneratedValue(strategy = GenerationType.AUTO) private int survey_id; public MOH731 (int survey_id, String uname)...

Mysterious claim of a missing { in eclipse

I have a case of a mysterious missing curly brace that I don't see any use for. Eclipse says, "Syntax error on token ";", { expected after this token". Either I am missing something very silly or there is something new I have to learn about Java. This is the...

Form submit portlet with Spring MVC

I'm trying to achieve a Liferay portlet of submit form using spring MVC. The model: package com.model; public class Person { String firstName; String middleName; public String getFirstName() { return this.firstName; } public String getMiddleName() { return this.middleName; } public void setFirstName(String firstName) { this.firstName=firstName; } public void setMiddleName(String middleName)...

Getting particular view from expandable listview

In my list view I have an textview in expandable group and I want to open the dialog when textview is clicked to fill the information through edittext and update textview. Problem: how could I get the groupview textview item in my fragment oncreateview() method....

How to pivot array into another array in Ruby

I have a multidimensional array like this one : myArray = [["Alaska","Rain","3"],["Alaska","Snow","4"],["Alabama","Snow","2"],["Alabama","Hail","1"]] I would like to end up with CSV output like this. State,Snow,Rain,Hail Alaska,4,3,nil Alabama,2,nil,1 I know that to get this outputted to CSV the way I want it I have to have output array like this: outputArray =[["State","Snow","Rain","Hail"],["Alaska",4,3,nil],["Alabama",2,nil,1]]...

Create array from another with specific indices

I have two arrays, one of data and one of indices: var data = [ 'h', 'e', 'l', 'l', 'o', ' ' ]; var indices = [ 4, 0, 5, 0, 1, 2, 2 ]; I would like to create a third array, using cells of data in order indicated...

How can implement long running process in spring hibernate?

as we know the struts interceptor execute and wait will take care of long running process by not getting the request to timeout and destroy it sends wait and at last the desired response i want to implement the same for long running process in spring and hibernate. Thanks....

Android String if-statement

I have a if-statement in the start of my app if (ready.equals("yes")){ ... } and later on my code I have ready="yes"; but the if statement is never called, why? The ready="yes"; is called from a background thread, is that why? public void DownloadFromUrl(final String fileName) { //this is the...

type conversion if flex

I am using Flerry as Java-Flex bridge for my Flex Desktop Application. How to convert List in Java to ArrayCollection in Flex Flex Code:- [Bindable]public var screenList:ArrayCollection; <flerry:NativeObject id="windowControllerObj" source="ls.window.EnumAllWindowNames" singleton="true" fault="windowControllerObj_faultHandler(event)"> <flerry:NativeMethod id="getWindowNames" name="getAllWindowNames" result="windowControllerObj_resultHandler(event)" fault="getWindowNames_faultHandler(event)"/>...

Javascript function to validate contents of an array

Here's what is asked: validItems(items) – this function receives a string array of items which are to be for a customer. The function returns an empty string indicating all item codes in the array are valid; otherwise the function returns the first invalid item code in the array. All item...

Interpreting hex dump of java class file

I understand the structure of a java .class file, but when I want to interpret the raw hex data I get a bit lost. This is a hex dump of a class file, excluding the header and constant pool. I understand the header to be the magic number, minor_version and...

Unfortunately, (My app) has stopped. Eclipse Android [duplicate]

This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers I'm a beginner in android developing and I'm trying to build a simple app but I'm getting this error in the emulator.(Unfortunately,(App) has unexpectedly stopped). LogCat package...

pointer to pointer dynamic array in C++

I've been having bad luck with dynamic pointers when I want to close it. why the application wrote to memory after end of heap buffer? how can I close my array? int main() { . . int **W; W = new int* [n]; for (int i=1; i <= n; i++)...

Get network interfaces on remote machine

I know in java we can do NetworkInterface.getNetworkInterfaces() to get all available network interfaces on local machine. Can we do similar thing where I can pass host name to get the NICs(with IPs) which are up and running?

Android Implicit Intent for Viewing a Video File

In my Android app, I have a button that when clicked, launches the external application of my choice to play a video (I gather that this is called an "implicit intent"). Here is the relevant Java code from my onCreate method. Button button = (Button) findViewById(; button.setOnClickListener ( new Button.OnClickListener()...

custom arraylist get distinct

is there any way to get the distinct values of a custom arraylist? public class mystatistic extends BaseActivity { public String objectid; public String playerid; public String playername; public String enemyid; public String enemyname; public String question; public mystatistik(String objectid, String playerid, String playername, String enemyid, String enemyname, String question)...

Get document on some condition in elastic search java API

As I know we can parse document in elastic search, And when we search for a keyword, It will return the document using this code of java API:- searchHits = node.client() .prepareSearch() .setIndices("indices") .setQuery(qb) .setFrom(0).setSize(1000) .addHighlightedField("file.filename") .addHighlightedField("content") .addHighlightedField("meta.title") .setHighlighterPreTags("<span class='badge badge-info'>") .setHighlighterPostTags("</span>") .addFields("*", "_source")...

Join files using Apache Spark / Spark SQL

I am trying to use Apache Spark for comparing two different files based on some common field, and get the values from both files and write it as output file. I am using Spark SQL for joining both files (after storing the RDD as table). Is this the correct approach?...

How to call MySQL view in Struts2 or Hibernate

I have a view in MySQL database CREATE VIEW CustInfo AS SELECT a.custName, a.custMobile, b.profession, b.companyName, b.annualIncome FROM customer a INNER JOIN cust_proffessional_info b ON a.cust_id=b.cust_id Is there any way that i can call this view using Struts2 or in Hibernate. I have tried to search it but could not...

Javadoc: Do parameter and return need an explicit type description

When Javadoc'ing, I don't know whether you should explicitly say whether the parameters are of type String or int. For example /** * This method does something * @param foo an object of type Foo * @param abc the number of doors, of type int * @return the number of...

Translating a character array into a integer string in C++

I was trying to achieve translating a character array into a integer string and corresponding character to their alphabetical order. For instance: A(a) = 0 , Z(z) = 25. string key_char = argv[1]; string key_num; for (int i = 0; i < key_char.length(); i++){ if (isalpha(key_char[i])){ if (islower(key_char[i])){ key_num[i] =...

Get element starting with letter from List

I have a list and I want to get the position of the string which starts with specific letter. I am trying this code, but it isn't working. List<String> sp = Arrays.asList(splited); int i2 = sp.indexOf("^w.*$"); ...

Get the value of the last inserted record

I am trying to get the stop_name of the last inserted row in the table with preparedStatement. How can I get the last inserted one? I appreciate any help. behavoiur table: CREATE TABLE IF NOT EXISTS behaviour( behaviour_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, mac VARCHAR(30) NOT NULL, stop_name VARCHAR(30)...

Selenium catch popup on close browser

I'm trying to test that when I close my window a popup shows with a warning message. I've tried both driver.close() and driver.quit() after making sure I'm on the proper window but this just terminates the process since my popup doesn't show. I could test it by using the awt...

Java dice roll with unexpected random number

I've written a simple Java program to display the results of 20 dice rolls on the console. The results I'm getting are listed below: 3 1 [email protected] 1 5 4 1 [email protected] 1 [email protected] [email protected] 1 6 [email protected] 1 [email protected] [email protected] 1 2 3 3 When I ran it for...

Android set clickable text to go one fragment to another fragment

I need to do something like this. Suppose I have 2 fragments A and B.There is a text which can be clickable in fragment A and when user click this text , he can go to fragment B. This example helped me to do it but I think it does...

Infinite loop with fread

I'm trying to allocate an array 64 bytes in size and then loop over the array indexes to put a read a byte each from the inputfile. but when I don't malloc() the array indexes, the loop stays in index0 (so each time it loops it replaces the content in...

Blank screen on GridView

I'm trying to create a GridView with an array of strings. These are XML, and MainActivity and Adapter, but what I get is a blank screen. I'm change the background, but the result is the same, but clicking on a point on the screen appears to me the toast stating...

App Not Downloading Newest Version Of File [Java]

Okay, I've been trying to figure this out for a few hours and it's starting to kill me. I wrote a primitive version checker for an app I work on every once and awhile. It's just a simple for fun project. The version checker has been a pain though. It...

How to do custom rounding of numbers in Java?

Suppose I want to round numbers that have mantissa greater than 0.3 'up' and those below 'down'. How can I do it in Java? The only thing that came to my mind was Math.round(), but I can't seem to make it follow a certain rule....

Using world coordinates

I am currently using pixels as units for placing objects within my world, however this can get tedious because I only ever place objects every 16 pixels. For example, I would like to be able to place an object at position 2 and have the object rendered at the pixel...

Merge and sum values and put them in an array

I'm retrieving values from an external source and apply a foreach loop to the results, with the code below. angular.forEach(data, function(value, key) { if (value.start_date > firstdayOfWeek && value.start_date < lastdayOfWeek) { console.log(value.firstname + ' - ' + value.distance); } else { //do nothing } }); The result is console...

Get elements containing text from array

I want to search all the elements containing any string in the array. For example I have following list of items <ul> <li>cricket bat</li> <li>tennis ball</li> <li>golf ball</li> <li>hockey stick</li> </ul> and this array var arr = ['bat', 'ball']; It should select all the elements having text bat and ball....

error: cannot find symbol class AsyncCallWS Android

I'm trying to rewrite the application in this, in Android Studio link, which is written in Eclipse. There are two problems, first problem is there is this line in the project : import com.example.webserviceactivity.R; I couldn't write this one on Android Studio. The second problem is, in this part of...

why java API prevents us to call add and remove together?

As per Java API- IllegalStateException - if neither next nor previous have been called, or remove or add have been called after the last call to next or previous remove()- Removes from the list the last element that was returned by next() or previous() (optional operation). This call can only...

How to block writes to standard output in java (System.out.println())

In Java, how to block code from writing to system out? My app calls a 3rd party library that spams logs by issuing numerous System.out.println() calls. I don't have legal rights to decompile and patch the library. I'm running Websphere 8.5.x Considered using System.setOut(PrintStream out), but that will effect the...

Javascript sort array of objects in reverse chronological order

I have an array of objects which holds a list of jobs and I would like to sort them in reverse chronological order as they would appear on a resume for example. I came up with the below solution which 'seems' to work but I was wondering if there is...

Logging operations in lightadmin

I have a Java web application which use Spring and Hibernate and I plan to use lightadmin to provide an administration interface. However, I found very little information about the logging part of lightadmin : if I have such an adminsitration interface, I would like that any operation made to...

Ruby: How to copy the multidimensional array in new array?

seating_arrangement [ [:first, :second, :none], [:first, :none, :second], [:second, :second, :first], ] I need to copy this array into new array. I tried to do it by following code: class Simulator @@current_state def initialize(seating_arrangement) @@current_state = seating_arrangement.dup end But whenever I am making any changes to seating_arrangement current_state changes automatically....

Get current latitude and longitude android

Requirement: 1.Sometimes(not everytime) I am getting latitude and longitude 0.0. 2.I want to know how to get the location update after user has enabled the gps from the settings. Here is my code public class GPSTracker extends Service implements LocationListener { private final Context mContext; // flag for GPS status...

Substring of a file

I have a file that is structure like this : var file = "a|b|c|d, a|b|c|d, a|b|c|d, a|b|c|d, a|b|c|d"; Now I would extract all letters "c" and "d" of this file and put those letter in array, structure like this: var array = [ [a,b,1], [a,b,2], [a,b,3], [a,b,4], [a,b,5] ]; How...