473,421 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Issue with loop in my code

JavaStudent07
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 2507
r035198x
13,262 8TB
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
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
I was wondering if you coult do the "String Data=inData.readLine(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 8TB
I was wondering if you coult do the "String Data=inData.readLine(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
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 8TB
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
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 8TB
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
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
r035198x
13,262 8TB
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.
Expand|Select|Wrap|Line Numbers
  1.  index = 0; 
  2. for each line in the file
  3. String[] two = line.split(")"); // or is it line.split("\\)")?
  4. numberArray[index] = two[1];
  5.  
Mar 24 '07 #11
i'm sorry, could you integrate it into my code or some other code for an example of actual coding, I'm not sure based on what you said, thats all new stuff to me...i'm sorry for the inconvenience

Steve
Mar 26 '07 #12
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1.  index = 0; 
  2. for each line in the file
  3. String[] two = line.split(")"); // or is it line.split("\\)")?
  4. numberArray[index] = two[1];
  5.  
Do you understand what the above is trying to do?
Mar 26 '07 #13
no i dont sorry
Mar 27 '07 #14
r035198x
13,262 8TB
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.
Is the data in your file numbered like the example above or is the data just like this

2 3 4 5
3 6 2 6
9 2 5 6
Mar 27 '07 #15

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

Similar topics

0
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...
17
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...
10
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:...
3
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...
4
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" ; //...
0
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...
29
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...
1
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. ...
9
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....
2
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.