Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Trouble splitting data in Java program

One thing that is wrong is that you have maxstudents set to 200, you allocate the studentnames array with size 200, but that means that the valid subscripts are 0 through 199, but your for loop uses a less than or equal test against 200:

        `for (int i = 0; i <=
maxstudents; i++)` 

That means that i is 200 on the last iteration, so in that iteration your code will effectively execute studentnames[200] = firstsplit[0]; and that will cause an ArrayIndexOutOfBoundsException.

The above, however, will be a problem if you reach the 200th iteration without breaking out of the for loop. Looking at the code, I do see that you are attempting to break if the input is "done", however that break statement is actually inside the nested for loop, so it does not break out of the outer loop. That test really should happen before you do the first split. There's no reason to even try to split if the input was "done", so also no reason to go into the nested for loop.

There are additional problems as well: The nested for loop should not be testing against maxstudents because it's the number of grades that you care about. I'll leave the rest of them for you to figure out - with a hint about one of them: you should be checking your input for errors.

Categories : Java

Related to : Trouble splitting data in Java program
Trouble splitting an array of integers using a delimiter
Just to illustrate flow logic: int[][] result = new int[][]; int resultIndex = 0; int[] chunk = new int[]; int chunkIndex = 0; for (int i=0; i<input.length; i++) { if (input[i] != number) { chunk[chunkIndex++] = input[i]; } else { if (chunk.length > 0) { result[resultIndex++] = chunk; chunk = new int[]; chunkIndex = 0; } } } if (chu

Categories : Java
Haskell Novice Trouble with Splitting a List in Half
The / is used for when you're happy to have a non-integer answer. Since you've already checked the number's even, you can hapily use integer division with div: halve :: [a] -> ([a], [a]) halve x | even len = (take half x, drop half x) | otherwise = error "Cannnot halve a list of odd length" where len = length x half = len `div` 2 (Personally I'd be happy to halve an o

Categories : Haskell
C: Return even number in array program by using pointers, why does my program crush after printing the result
for(i = 0; i <= sizeof(test); i++){ printf("%d ", *test[i] ); } sizeof(test) isn't the number of elements in the array test, it's sizeof(int*) which is 8 (bytes), assuming you're on a 64-bit system. It's returning the size of a pointer to a memory address, not the actual length of the array. So your loop goes outside the bounds of the array which probably causes your problem. Al

Categories : C
Changing a C/++ OpenCV program to CUDA from video stabilization program
Since OpenCV 3.0, a CUDA implementation of video stabilization is available. It is recommended to use the already available implementation instead of writing your own unless you are sure that your version would be better or faster. Here is a minimal code demonstrating how to use the OpenCV video stabilization module to stabilize a video. #include <opencv2/highgui.hpp> #include <opencv2/

Categories : C++
Making a program with a range that can change during the course of the program (Java)
private static void RepeatedGuesses() { while (1 != UserAnswer) { UserAnswer = reader.nextInt(); if (2 == UserAnswer) { rFinder = (int) (generator.nextInt(100 - guess)); guess = rFinder + guess; System.out.print(guess + ": Is this your number? Enter Yes or enter Higher or enter Lower:"); } else if (3 == Use

Categories : Java
Recently Add
Concurrent collection to 50/50 read/write
How to get unique members of object class (groupofUniqueNames) from an ldap server using java
Custom error reporting: how to log down function arguments (and possibly locals) in an exception handler?
Websphere MQ message redelivery
How to use BigDecimal to achieve following code instead of using double or float?
What exactly do the service() method of this HttpServlet?
Why does the Java API use int instead of short or byte?
Hibernate. One to one mapping without cross references
How to pass array to a java method
BooleanFieldEditor doesn't load value from PreferenceStore
NoClassDefFoundError when I call the class through commnad line
Shopizer Search
Java - Bank System + Transaction Function
Hadoop security using Apache DS / Apache Directory Studio
Multiple property-placeholder with overlapping locations does not work?
could not remove/add jpanel in jframe
Java garbage collection verbose not working
If child class has a variable with same name as private variable in parent what will be used?
Jackson parse json with a one-to-many relationship in a single step
Excel opens wrong view after generating in Apache POI
On Switch How to use logic operator on case JAVA
Java: What is the absolut first second in Calendar?
Waiting One Second for a button click, if button not clicked call function
Fastest way to extract part of a large JSON File
copy directory operation using linux command in java
Figuring out how to Format Printing
Why does @FunctionalInterface have a RUNTIME retention?
Collision detection Libgdx rectangles
Cannot find symbol in method changeRecL but declared in main method
Receiving " Connection reset" when connecting from dotnet client to a java server
© Copyright 2017 Publishing Limited. All rights reserved.