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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:57:31+00:00 2026-06-11T00:57:31+00:00

I was interviewed yesterday and this question arise: public class Main { public static

  • 0

I was interviewed yesterday and this question arise:

public class Main {

    public static void main(String[] args) {

        // Code fragment must prints true if the double variables x and y are both
        // strictly between 0 and 1 and false otherwise. 

        // Assuming args will be always correct (double) input, 
        // Where's the safety bug?

        double x,y;

        x = Double.parseDouble(args[0]);
        y = Double.parseDouble(args[1]);

        System.out.println( (0 < x && x < 1) && (0 < y && y < 1)? true : false );
    }
}

I wrote there were no bug anywhere, I mean, code works. Back at home, tried and indeed it works. But although I did get the job, this question was my only bad one, and I can’t get it out of my head (it seams fair straight simple). I believe I don’t even understand what a safety bug is so, my question then is:

What’s a safety bug and does this code indeed have one?

UPDATE:

After response I put some related resources:

Eric Lippert‘s Why does JScript have rounding errors?

  • 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-11T00:57:32+00:00Added an answer on June 11, 2026 at 12:57 am

    Judging from the comment in the source:

    Assuming args will be always correct (double) input, Where’s the safety bug?

    There exists a case in which the program will deliver a wrong output, and there seems to be no dubious except the expression itself:

    (0 < x && x < 1) && (0 < y && y < 1)

    Although I haven’t tested it, there may be a problem when this expression is confronted with one of the edge cases for either x or y: NaN, +/- infinity and maybe even -0.0.

    Also there exist definitively valid inputs which may violate the logical expectation of the user due to the limited precision with which number are represented in a double (e.g. x = 1E-400 is greater than 0, but parses as 0, so the expression delivers false although the user would expect true).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

An interviewer asked me this: class Employee{ private string empname; public String getEmpname() {
Yesterday in my interview I was asked this question. (At that time I was
Had this question in the interview yesterday. Which is better to use? Infix(with parenthesis)
this is an interview question my friend was asked yesterday. The question was something
I have a public class public class Interview { public int InterviewId; public string
For this question, a pair in a string is defined as a situation where
Yesterday i had a question in an interview which i thought i could find
Its a interview question. Interviewer asked this basic shell script question when he understand
An interviewer recently asked me this question: given three boolean variables, a, b, and
The interviewer showed me a code like this and asked me whether it would

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.