Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7637499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:57:20+00:00 2026-05-31T07:57:20+00:00

I was wondering if it is possible to make a loop for an array

  • 0

I was wondering if it is possible to make a loop for an array of strings that i want to evaluate in my code. I want to do more than one binary number at a time. So far I have this working correctly, however I cant figure our how to make it evaluate more than one binary number at a time. Thank you.

 package twoComplement;

public class bintodec {

public static void main (String[] args)throws java.io.IOException {

int number,
    digit1,
    digit2,
    digit3,
    digit4,
    digit5,
    digit6,
    digit7,
    digit8,
    result;

String num = "11100111";

number = Integer.parseInt(num);

digit1 = ((number % 100000000) - (number % 10000000 % 10000000)) / 10000000;
digit2 = ((number % 10000000) - (number % 10000000 % 1000000)) / 1000000;
digit3 = ((number % 1000000) - (number % 1000000 % 100000)) / 100000;
digit4 = ((number % 100000) - (number % 100000 % 10000)) / 10000;
digit5 = ((number % 10000) - (number % 10000 % 1000)) / 1000;
digit6 = ((number % 1000) - (number % 1000 % 100)) / 100;
digit7 = ((number % 100) - (number % 100 % 10)) / 10;
digit8 = (number % 10);

result = (digit1 * -128) + (digit2 * 64) + (digit3 * 32) + (digit4 * 16) + (digit5 * 8) + (digit6 * 4) + (digit7 * 2) + (digit8 * 1);

System.out.println ( "Binary number: " + num + "\nDecimal Number: " + result);
System.out.println();
System.exit( 0 );

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:57:21+00:00Added an answer on May 31, 2026 at 7:57 am

    Yes, this is the purpose of loops 😉 An advanced for loop is the best way to iterate through an array. You can also iterate through collections (IE: ArrayList), which makes it easier to add new items.

    String[] numbersToEvaluate = new String[]{"11100111", "100101", "10101101"};
    
    for (String num: numbersToEvaluate)
    {
        number = Integer.parseInt(num);
    
        digit1 = ((number % 100000000) - (number % 10000000 % 10000000)) / 10000000;
        digit2 = ((number % 10000000) - (number % 10000000 % 1000000)) / 1000000;
        digit3 = ((number % 1000000) - (number % 1000000 % 100000)) / 100000;
        digit4 = ((number % 100000) - (number % 100000 % 10000)) / 10000;
        digit5 = ((number % 10000) - (number % 10000 % 1000)) / 1000;
        digit6 = ((number % 1000) - (number % 1000 % 100)) / 100;
        digit7 = ((number % 100) - (number % 100 % 10)) / 10;
        digit8 = (number % 10);
    
        result = (digit1 * -128) + (digit2 * 64) + (digit3 * 32) + (digit4 * 16) + (digit5 * 8) + (digit6 * 4) + (digit7 * 2) + (digit8 * 1);
    
        System.out.println ( "Binary number: " + num + "\nDecimal Number: " + result);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering if its possible to make the following code more concise: $('#americasTrigger').hover( function
i'm wondering about this possibility. Is it possible to make our code written in
I was wondering if it was possible to make a Rebar that goes vertically
I'm wondering if its possible to make a program in C++ that can press
I was wondering if it's possible to make more of the styling buttons in
I was wondering if its possible to make the following answer more generic, in
I was wondering how/if it was possible to make marker icons appear larger than
I'm wondering if it's possible to make a method which behaves differently when called
I am wondering whether it is possible to make dynamic variables in Java. In
I was wondering if it is possible to make a new file inside the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.