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

  • Home
  • SEARCH
  • 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 3721824
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:41:18+00:00 2026-05-19T05:41:18+00:00

in java, i have an array of floats, some of them are negative numbers,

  • 0

in java, i have an array of floats, some of them are negative numbers, like :

3.04, 9.02, -4.2, -3.21, 0.02, -0.34

I only want to get the float numbers higher than 2, so I used :

if(number > 2.0 ) print.. etc

but what i get is not only the numbers >2, also the negative numbers :

3.04, 9.02, -4.2, -3.21

what could be the problem ?

  • 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-19T05:41:19+00:00Added an answer on May 19, 2026 at 5:41 am

    Based on comments and question, assuming we have a file named numbers.txt with content:

    3.04 
    9.02 
    -4.2 
    -3.21 
    0.02 
    -0.34
    

    this code should do the trick (I ommited exception handling for readibility):

    float[] floats = new float[100];  // adjust as needed
    
    String fileName = "numbers.txt";
    File f = new File(fileName);
    BufferedReader br = new BufferedReader(new FileReader(f));
    
    String line = "";
    
    int i = 0;
    
    while( (line = br.readLine()) != null) {
    
        if(line == null || line.isEmpty()) continue;  // just in case there are empty lines in file
        floats[i] = Float.parseFloat(line);
        i++;
    }
    
    br.close();
    
    for (float number : floats) {
        if (number > 2.0) {
            System.out.println(number);
        }
    }
    

    Output:

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

Sidebar

Related Questions

I have a float array in java and want to convert each element to
I have an array of floats and I would like to convert it to
I have a Java array defined already e.g. float[] values = new float[3]; I
am having problem in Saving some data in my Java code. I have like
I have two dimensional float array as below {0.2,0.0,0.3,0.0,0.0} {0.4,0.1,0.0,0.0,0.9} {0.0,0.0,0.0,0.3,0.6} I want to
Suppose I have an array of class values in Java and I want to
I have a large array. I have some Java code for identifying indices for
I have a Java method which returns an array of doubles. I would then
I am writing jython application with eclipse SWT/JFace. I have to pass float array
I have a vector of float arrays i.e. Vector . I want to convert

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.