473,657 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issue with loop in my code

JavaStudent07
64 New Member
I have a feeling it is something simple troubling me, I just cant find out what that problem is. The progam is SO CLOSE! please help me.

Expand|Select|Wrap|Line Numbers
  1. public class BubbleSort2
  2. {
  3. public static void main (String args[]) throws Exception
  4. {
  5. String filage="";
  6. String linetext;
  7.  
  8. BufferedReader inWords=new BufferedReader(new InputStreamReader(System.in));
  9. System.out.println("Please input the name of the file from which the data will be acquired.  Be sure to use the entire path.");
  10. filage=inWords.readLine();
  11.  
  12. while((linetext=inWords.readLine())!=null)
  13. {
  14. Sort(filage);
  15. }
  16. }
that little bit is the problem, I can compile and run, but it only executes the first line of the file and asks for the file again, then does the first line AGAIN and asks for the file AGAIN and so on and so forth repeating untill I terminate the box. If you have any suggestions, me and my friend are having the same problem, thanks for your time,

Steve
Mar 20 '07 #1
14 2518
r035198x
13,262 MVP
I have a feeling it is something simple troubling me, I just cant find out what that problem is. The progam is SO CLOSE! please help me.

Expand|Select|Wrap|Line Numbers
  1. public class BubbleSort2
  2. {
  3. public static void main (String args[]) throws Exception
  4. {
  5. String filage="";
  6. String linetext;
  7.  
  8. BufferedReader inWords=new BufferedReader(new InputStreamReader(System.in));
  9. System.out.println("Please input the name of the file from which the data will be acquired. Be sure to use the entire path.");
  10. filage=inWords.readLine();
  11.  
  12. while((linetext=inWords.readLine())!=null)
  13. {
  14. Sort(filage);
  15. }
  16. }
that little bit is the problem, I can compile and run, but it only executes the first line of the file and asks for the file again, then does the first line AGAIN and asks for the file AGAIN and so on and so forth repeating untill I terminate the box. If you have any suggestions, me and my friend are having the same problem, thanks for your time,

Steve
This is only ossible if you have print out in the sort method which you decided not to post. Please post the whole class.
Mar 20 '07 #2
JavaStudent07
64 New Member
This is only ossible if you have print out in the sort method which you decided not to post. Please post the whole class.
Expand|Select|Wrap|Line Numbers
  1. /*
  2. Steve Glasser
  3. January 6,2007
  4. BubbleSort
  5. */
  6.  
  7. import java.io.*;
  8. import java.util.*;
  9.  
  10. public class BubbleSort2
  11. {
  12. public static void main (String args[]) throws Exception
  13. {
  14. String filage="";
  15. String linetext;
  16.  
  17. BufferedReader inWords=new BufferedReader(new InputStreamReader(System.in));
  18. System.out.println("Please input the name of the file from which the data will be acquired.  Be sure to use the entire path.");
  19. filage=inWords.readLine();
  20.  
  21. while((linetext=inWords.readLine())!=null)
  22. {
  23. Sort(filage);
  24. }
  25. }
  26. //V^V^V^V^V^V^V^V^V^V^V^V^^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^
  27. public static void Sort(String filage)throws Exception
  28. {
  29. char DataBits='A';
  30. String Number="";
  31. String Data="";
  32. char array[];
  33. int PlaceHolder=0;
  34. int ArrayLength=0;
  35. int intN=0;
  36.  
  37. Data=seekBufferedReaderData(filage);
  38.  
  39. System.out.println(Data);
  40. array=Data.toCharArray();
  41. ArrayLength=array.length;
  42. System.out.println(ArrayLength);
  43. DataBits=Data.charAt(PlaceHolder);
  44. final int ARRAY_SIZE=(ArrayLength-1);
  45. int NumArray[];
  46. NumArray=new int[ARRAY_SIZE];
  47.  
  48.  
  49. while(PlaceHolder<ArrayLength)
  50. {
  51.  
  52. while(DataBits!=' ')
  53. {
  54. if(PlaceHolder<ArrayLength)
  55. {
  56. System.out.println("PlaceHolder: "+PlaceHolder);
  57.  
  58. System.out.println("Character:"+DataBits);
  59. Number=(Number+DataBits);
  60. PlaceHolder++;
  61. DataBits=(Data.charAt(PlaceHolder));
  62. }
  63. }
  64.  
  65. NumArray[intN]=seekArray(Number);
  66. System.out.println("Final Concatenated Result of While: "+NumArray[intN]);
  67. intN++;
  68. Number="";
  69.  
  70. System.out.println("PlaceHolder: "+PlaceHolder);
  71. System.out.println("Character: *Blank*");
  72. PlaceHolder++;
  73.  
  74. if(PlaceHolder<ArrayLength)
  75. {
  76. DataBits=(Data.charAt(PlaceHolder));
  77. }
  78. }
  79. seekAverage(NumArray, intN);
  80. System.out.println("In sorted order, the numbers go:");
  81. seekOrder(NumArray, intN);
  82. }
  83.  
  84. //V^V^V^V^V^V^V^V^V^V^V^V^^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^
  85. public static String seekBufferedReaderData(String filage)throws Exception
  86. {
  87.  
  88. BufferedReader inData=new BufferedReader(new FileReader(filage));
  89. String Data=inData.readLine();
  90.  
  91.  
  92. return(Data);
  93. }
  94. //V^V^V^V^V^V^V^V^V^V^V^V^^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^
  95. public static int seekArray(String Number)
  96. {
  97. int Numerical=Integer.parseInt(Number);
  98.  
  99. return(Numerical);
  100. }
  101.  
  102. //V^V^V^V^V^V^V^V^V^V^V^V^^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^
  103. public static void seekOrder(int NumArray[], int intN)
  104. {
  105. int swapped=0;
  106. int swap=0;
  107. int N=0;
  108.  
  109.  
  110. while(swapped==0)
  111. {
  112. swapped=1;
  113.  
  114. for(N=0; N<intN-1;N++)
  115. {
  116.        if(NumArray[N]>NumArray[N + 1]) 
  117.            {     
  118.        swap=NumArray[N];
  119.        NumArray[N]=NumArray[N+1];
  120.        NumArray[N+1]=swap;
  121.        swapped=0; 
  122.            }
  123. }
  124. }//end for
  125. seekPrint(NumArray, intN);
  126. }//end Order
  127. //V^V^V^V^V^V^V^V^V^V^V^V^^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^
  128. public static void seekAverage(int NumArray[], int intN)
  129. {
  130. double dblAverage=0.00;
  131. int intTest=0;
  132.  
  133. for(intTest=intN-1; intTest>=0; intTest--)
  134. {
  135. dblAverage=dblAverage+NumArray[intTest];
  136. }
  137. dblAverage=(dblAverage/intN);
  138. System.out.println("The Average of the Numbers is: "+dblAverage);
  139. }
  140. //V^V^V^V^V^V^V^V^V^V^V^V^^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^
  141. public static void seekPrint(int NumArray[], int intN)
  142. {
  143. int intTest=0;
  144.  
  145. for(intTest=intN-1; intTest>=0; intTest--)
  146. {
  147.  
  148. System.out.println("Array #: (test for subscript)"+intTest+"  "+NumArray[intTest]);
  149. }
  150. }
  151. }
Mar 21 '07 #3
JavaStudent07
64 New Member
I was wondering if you coult do the "String Data=inData.rea dLine(Counter); " to read each line and just bump it up but it said it couldn't resolve the symbol, I pretty much am out of guesses at this point.
Mar 21 '07 #4
r035198x
13,262 MVP
I was wondering if you coult do the "String Data=inData.rea dLine(Counter); " to read each line and just bump it up but it said it couldn't resolve the symbol, I pretty much am out of guesses at this point.
What do you want the lines

Expand|Select|Wrap|Line Numbers
  1.  
  2. String filage="";
  3. String linetext;
  4.  
  5. BufferedReader inWords=new BufferedReader(new InputStreamReader(System.in));
  6. System.out.println("Please input the name of the file from which the data will be acquired.  Be sure to use the entire path.");
  7. filage=inWords.readLine();
  8.  
  9. while((linetext=inWords.readLine())!=null)
  10. {
  11. Sort(filage);
  12. }
  13.  
  14.  
to do?
Mar 21 '07 #5
JavaStudent07
64 New Member
I want them to find the data file inputted at the command prompt and run the program for each line with the while statement
Mar 22 '07 #6
r035198x
13,262 MVP
I want them to find the data file inputted at the command prompt and run the program for each line with the while statement
Then
Expand|Select|Wrap|Line Numbers
  1. Sort(filage);
should be
Expand|Select|Wrap|Line Numbers
  1.  Sort(linetext);
Mar 22 '07 #7
JavaStudent07
64 New Member
Expand|Select|Wrap|Line Numbers
  1. public static void main (String args[]) throws Exception
  2. {
  3. String filage="";
  4.  
  5. BufferedReader inWords=new BufferedReader(new InputStreamReader(System.in));
  6. System.out.println("Please input the name of the file from which the data will be acquired.  Be sure to use the entire path.");
  7.  
  8.  
  9. while((filage=inWords.readLine())!=null)
  10. {
  11. Sort(filage);
  12. }
  13.  
  14. }
^^^^
that gives the same repeating results
Mar 22 '07 #8
r035198x
13,262 MVP
Expand|Select|Wrap|Line Numbers
  1. public static void main (String args[]) throws Exception
  2. {
  3. String filage="";
  4.  
  5. BufferedReader inWords=new BufferedReader(new InputStreamReader(System.in));
  6. System.out.println("Please input the name of the file from which the data will be acquired. Be sure to use the entire path.");
  7.  
  8.  
  9. while((filage=inWords.readLine())!=null)
  10. {
  11. Sort(filage);
  12. }
  13.  
  14. }
^^^^
that gives the same repeating results
So filage is actually a line of data from your file.
Now have a look at
Expand|Select|Wrap|Line Numbers
  1.  Data=seekBufferedReaderData(filage);
  2.  
.

And that method takes the fileage and tries to open a file called filage!
Mar 22 '07 #9
JavaStudent07
64 New Member
sorry, I dont follow. I just want to fill an array with each subscript being a different line of the test values

EX.
1.) 2 3 4 5
2.) 3 6 2 6
3.) 9 2 5 6

i want NumberArray[0]==2 3 4 5 and NumberArray[1]==3 6 2 6, etc etc. I think I can work it out if I can get some direction on that.
Mar 23 '07 #10

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

Similar topics

0
1064
by: Avi Schwartz | last post by:
In this issue the following statement is made: "In plpgsql, you cannot run a dynamic SELECT statement and be able to do anything with the selected data. You cannot assign the selected value to a variable or return the selected value from the function. You can, however, easily construct INSERT, UPDATE and DELETE statements as well a DDL (Data Definition Language: CREATE, ALTER, etc.)" This is not my experience. For example, I am doing...
17
4201
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset Set rs = Me.RecordsetClone rs.Find "=" & lngContractID If Not rs.EOF Then Me.Bookmark = rs.Bookmark I must site the Heisenberb Uncertainty Principal here, as it
10
3583
by: Eric | last post by:
I'm looking at this page in the MSDN right here: ms-help://MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemcollectionsarraylist classsynchronizedtopic2.htm (or online here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsicollectionclasssyncroottopic.asp) And I'm interested in locking an ArrayList during the entire enumeration, as shown in the example code. My problem is that I'm STILL...
3
1863
by: IntraRELY | last post by:
I have a loop that loops through this sub. However, I recieve an WebException error in my try statement. "An exception occurred during a WebClient request." This message doesnt happen when I am only looping throught the sub once, however when I process multiple records, I recieve this error for every record after the first one. And the images that is downloaded does show up for all records processed. So everything works there is just an...
4
1416
by: Mrinal Kamboj | last post by:
Hi , I am confused that's is not even correctly mentioned in MSDN , if my code snippet works , have a look at this : 1. string s = {"1", "2","3"} ; foreach(string ss in s) { ss = "4" ; // Compilation error as foreach loop is Read Only as
0
1405
by: matchine | last post by:
This is a recommendation based on my research on an issue with the transfer text functionality. The comments below were from a tech I approched for help. "The transfer text process blocked after importing 6139 records each time on my side. After further research, there maybe a memory leak in TransferText. When the number of records exceeds its limitation, the transfer process blocked. Therefore, please abandon TransferText and write...
29
1928
by: ataanis | last post by:
Hi, I have the following statement, and i'm trying to understand why when I do the second print it's giving me segmentation fault, both name and s_aliases are char arrays e.g THE FIRST PRINT WORKS FINE , which means that the aliases are in s_aliases char names and char s_aliases, h is a structure , that contains s_aliases defined as
1
5315
by: Ryan | last post by:
Hello. I was hoping that someone may be able to assist with an issue that I am experiencing. I have created an Access DB which imports an Excel File with a particular layout and field naming. Next the user can go into a Form which basically a dynamic query with a friendly interface that eventually outputs a table that is stored in the DB as well as exported to a CSV file. The CSV file is then used with a vendor solution to fill in...
9
3048
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped. Below you will find the code I've written and the error that results. I'm hoping that someone can give me some direction as to what syntax or parameter is missing from the code that is expected by VBA. Overview: I'm trying to copy calculated...
2
5145
by: pmlane2001 | last post by:
I have a PHP SOAP XML file size problem that I was wondering if anyone has seen before. I have an XML file that when I put it through my PHP script with 270 lines (13,082 KB) it works fine. If I make it 271 lines (13,112 KB), it causes the script to end with a soap fault. I've tried adding substance to the 270 lines to make the file bigger with out adding lines, but it didn't fail. I've installed everything on a second development box...
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.