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 8823495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:22:15+00:00 2026-06-14T06:22:15+00:00

I am writing a simple java and bash program, but it is not working.

  • 0

I am writing a simple java and bash program, but it is not working. Let me know where is wrong.

Bash:

    for i in [1..100]; do 
         echo $i
         java prob2 $i 
    done

Java:

import java.io.*;

public class prob2
{
    public static void main( String[] args )
    {
            int l = args.length;
            if ( l == 1 )
            {
                    int num = Integer.parseInt(args[0]);
                    while ( num != 0 && num != 1)
                            num = num - 2;
                    if ( num == 0 )
                            System.out.println("Even");
                    else if ( num == 1 )
                            System.out.println("Odd");
            }
    }
}

The error I’m getting is:

Exception in thread “main” java.lang.NumberFormatException: For input string: “[1..100]” at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:492) at java.lang.Integer.parseInt(Integer.java:527) at prob2.main(prob2.java:10)

  • 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-06-14T06:22:16+00:00Added an answer on June 14, 2026 at 6:22 am

    That’s not how you would do a bash loop. Try this:

    for i in `seq 1 100`; do 
         echo $i
         java prob2 $i 
    done
    

    As an aside, a faster algorithm for determining if a number is odd or even is to take it modulo 2:

    if (num % 2 == 0) {
        System.out.println("Even");
    } else {
        System.out.println("Odd");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a simple Java program to send mail, but am getting errors.
I'm writing a simple program to call a Java function from my C program.
I am writing simple parallel program in C++ using OpenMP. I am working on
I'm writing a simple text editor in java, I have done it before now
I'm working on writing a simple Prolog interpreter in Java. How can I find
I have never really done any serious testing other then writing some simple Java
I'm writing a very simple Java Game. Let me describe it briefly: There are
I'm writing a simple program in Java which includes a KeyListener with the following
My java program keeps thinking that every new file is not a file but
I'm writing a simple painting program using Java, and I want some method to

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.