472,779 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

Code doesn't work inside "for" statement

I am new to Java and would greatly appreciate any help. Here is some code I am working on as basically a proof of concept. I am using a "throws FileNot FoundException". The problem is that when i run the program nothing happens. There are no errors but there is also no output. This same code worked without the "for" statement for just the first number.

Expand|Select|Wrap|Line Numbers
  1. Scanner reader = new Scanner(new FileReader("test.txt"));
  2.         for (i=0;i > 10;i++){
  3.             read = reader.nextDouble();
  4.             System.out.println(read);
  5.         }
Here is the text file that it is reading from.

Expand|Select|Wrap|Line Numbers
  1. 12.345
  2. 13.345
  3. 14.345
  4. 15.345
  5. 16.345
  6. 17.345
  7. 18.345
  8. 19.345
  9. 20.345
  10. 21.345
Mar 22 '09 #1
2 1714
11,448 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. for (i=0;i > 10;i++){ 
  2.    read = reader.nextDouble(); 
  3.    System.out.println(read); 
Look at your code again; a for loop works like this:

Expand|Select|Wrap|Line Numbers
  1. for (<initialize>; <condition>; <increment>)
  2.    <statements>;
First the <initialize> section is executed once; then the <condition> is tested; if it has a true value then <statements> are executed and finally the <increment> part is executed. Then the <condition> is tested again and the cycle repeats as long as <condition> is true; otherwise the loop finishes.

Look at your <condition>: it isn't true the first time it is tested (0 < 10) so your loop terminated immediately. You probably wanted to write i < 10.

kind regards,

Mar 22 '09 #2
Oh wow! Even I should have been able to catch that one! Thanks alot for the help tho!
Mar 22 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: New Guy | last post by:
Hello, First, I want to apologize for posting this message to multiple groups. (1) I have a hard time finding any info and (2) this is not a school assignment. I am trying to create in my...
by: Doug Telford | last post by:
I recently purchased the referenced book, but the author's (Phil Hanna) web site is not working (expired domain name?). Could someone point me to an alternate site for the eratta, and source...
by: Frank Meng | last post by:
Hi. I wrote a program to get the directory of "Recycle Bin" with SHGetSpecialFolderLocation . It works for "Recent", "SendTo", etc. but it doesn't work for "Recycle Bin". At...
by: SKB | last post by:
Hi, I want to implement the "outer join" functionality in Java. Can somebody explain the pseudo code for the same. OR what needs to be done to extend the hash-join Java code of equijoin(I have the...
by: Andre | last post by:
Hi, Does anyone know whether the ECMA, or an other standard document, specifies a maximum for the value that can be pass to the setTimeOut() function in Javascript? Andre
by: abilashnn | last post by:
'm attempting to send a mailto: and include a link in the body. Has anyone done this? I have one problem with this. One appln have a link to send an email using “mailto:”. Previosly this...
by: jmbn2k | last post by:
Hi... Iam a fresher from 2006 pass out.This was an interview question asked by a company for which am supposed to giv the answers as soon as possible within Monday..... The problem...
by: Leonnhy | last post by:
HI, I'm a beginner in using MS Access. What's the code for the bring forward figure in current sales report I create as follows:- Once I click on the sales report, it will show me the date range...
by: Deniz Dogan | last post by:
Hello. I am writing a program which has to send a signal (SIGUSR2 F.Y.I.) to a certain process, which I only know the name of, i.e. I need the PID for that process. How can I do this in C or...
by: Dave Navarro | last post by:
I can send a text message to my cell phone by just sending an email to my cell number @att.com. Where can I get the protocol for other carriers? My boss wants me to set up a form on our...
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.