Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Method call getting completely ignored.

DynamiAug 3 2017 — edited Aug 7 2017

Hello. I was making a program that converts decimal numbers to binary numbers.

And I made one method for each step. that is,

1. take the binary number and separate each digit, and then take each digit and add to an arraylist in the reverse order.(method name: Binary2ArrayList)

2.check each digit and if it is "1" add the a power of 2 equivalent to the column(Method name: Arraylist2Decimal)

Basically,

0.(input) 110

1.  1 1 0 -> 0 1 1

2.   [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]

       0  1  1

       (ignore, add,add)

3. 2+4 = 6

result = 6

I know this is not the most optimal way to do it, but I'm doing it this way so i can practice more coding with a single project.

but what happened, is that my program completely ignores the "Arraylist2Decimal" method even after called.

I will be really grateful if someone could help me.

(Using netbeans IDE)

Code:

package javaapplication1;

import java.util.Scanner;

import java.util.ArrayList;

 

    public class Binary2Decimal2Binary {

    private static long binary1;

    private static long binary2;

    private final static ArrayList POWERSOF2 = new ArrayList<Integer>();

    private final static ArrayList<Integer> SEPARATED2 = new ArrayList<Integer>();

    private static int result1 = 0;

    private static int result2 = 0;

    private final static ArrayList<Integer> SEPARATED1 = new ArrayList<Integer>();

    static public int getNthDigit(int number, int n) {  

  return (int) ((number / Math.pow(10, n - 1)) % 10);

}

    static void binary2ArrayList(long binary1, long binary2){

    String separating1 = String.valueOf(binary1);

    for(int i = 1; i < separating1.length() + 1; i++) {

        int j =(int) getNthDigit((int)binary1, i);

        SEPARATED1.add(j);}

     String separating2 = String.valueOf(binary2);

     for(int x = 1; x < separating2.length() + 1; x++) {

         int y =(int) getNthDigit((int)binary2,x);

         SEPARATED2.add(y);

     }

     System.out.println("Debugger 1 :" + SEPARATED1);

      System.out.println("Debugger2 :" + SEPARATED2);

   

    }

    static void Arraylist2Decimal(){

       for(int i = 1; i == SEPARATED1.size() + 1; i++) {

         int intValue = (int)SEPARATED1.get(i);

         int addition = (int) POWERSOF2.get(i);

         if(intValue == 1){

             result1 += addition;

         }

       System.out.println("Debugger 3:" + result1);

       }

       for(int k = 1; k == SEPARATED2.size() + 1; k++) {

         int intValue = (int) SEPARATED2.get(k);

         int addition = (int) POWERSOF2.get(k);

         if(intValue == 1){

             result2 += addition;

         }

         System.out.println("Debugger 4 :" + result2);

    }};

        public static void main(String[] args) {

            POWERSOF2.add(1);

            POWERSOF2.add(2);

            POWERSOF2.add(4);

            POWERSOF2.add(8);

            POWERSOF2.add(16);

            POWERSOF2.add(32);

            POWERSOF2.add(64);

            POWERSOF2.add(128);

            POWERSOF2.add(256);

            POWERSOF2.add(512);

            POWERSOF2.add(1024);

            POWERSOF2.add(2048);

            POWERSOF2.add(4096);

            POWERSOF2.add(8192);

            POWERSOF2.add(16384);

            POWERSOF2.add(32768);

            System.out.println("Powers of 2:" + POWERSOF2);

           Scanner scan = new Scanner(System.in);

     System.out.println("Input first binary number.");

     binary1 = scan.nextLong();

     System.out.println("Input second binary number.");

     binary2 = scan.nextLong();

     scan.close();

     binary2ArrayList(binary1,binary2);

     Arraylist2Decimal();

     System.out.println("First Number Converted:" + result1);

     System.out.println("Second Number Converted:" + result2);

 

 

 

        }}

input : 110

101

output :

Debugger 1 :[0, 1, 1]

Debugger2 :[1, 0, 1]

First Number Converted:0

Second Number Converted:0

(Note that "Debugger 3"println and "Debugger 4"println is not working.)

Comments

thatJeffSmith-Oracle
Answer

That indicates you should have an installation of Oracle Database on your personal machine.
Do you?

Marked as Answer by User_IQS4Z · Mar 13 2022
cormaco

"lsnrtl" is not recognized as an internal or external command, program or executable batch file.
You mistyped lsnrctl here.

User_IQS4Z

upsss! I'm sorry, I made a mistake in writing. I typed the correct command, I typed: lsnrctl

User_IQS4Z

Yes, I also believe that I should have installed an Oracle Database!
Thanks in advance! @thatjeffsmith-oracle and @cormaco

EdStevens

So, when you typed the correct command, what was the result? If it was still "is not recognized as an internal or external command, program or executable batch file.",

Then just like any other command that returns that error, it is because the executable ('lsnrctl' in this case) is not located in any directory that is part of your system PATH. Either you have not installed Oracle database on this machine (the one where you issued 'lsnrctl'), or you have failed to set the system environment variable PATH. Actually, that should have been done by the installation, if on Windows.
You said, "I also believe that I should have installed an Oracle Database". Well either you did or you didn't. And it's not something trivial that you would have done without knowing for sure. If you are relying on the installation of SQL Dev, then no you have not installed an Oracle database. SQL Dev is just an IDE - a client. It is not a database, and does not have a database bundled in with it.

User_IQS4Z

Thanks for your answer.
Yes, I installed Oracle Database 19c @edstevens1
Now, the error I get when I try to create the connection is:
Status: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
(CONNECTION_ID=/7ii3DHaT2Gz+eJN44XCEQ==)

I

User_IQS4Z

If I type >lsnrctl status
The message I am receiving is: listener is already started but it does not support any services .
and if I type >oraenv it
Tells me:
"oraenv is not recognized as an internal or external command,
program or executable batch file"

EdStevens

If I type >lsnrctl status
The message I am receiving is: listener is already started but it does not support any services .
That means your database is not started.
and if I type >oraenv it
Tells me:
"oraenv is not recognized as an internal or external command,
program or executable batch file"
'oraenv' exists only on *nix systems, not on Windows. what were you expecting by trying to execute it?

1 - 8
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 4 2017
Added on Aug 3 2017
5 comments
328 views