Question
JAVA getting the following errors: Project4.java:93: error: ']' expected arr[index] = newVal; // LEAVE THIS HERE. DO NOT REMOVE ^ Project4.java:93: error: ';' expected arr[index]
JAVA getting the following errors:
Project4.java:93: error: ']' expected arr[index] = newVal; // LEAVE THIS HERE. DO NOT REMOVE ^ Project4.java:93: error: ';' expected arr[index] = newVal; // LEAVE THIS HERE. DO NOT REMOVE ^ Project4.java:93: error:
MY CODE:
import java.util.*; import java.io.*;
public class Project4 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { if (args.length < 1 ) { System.out.println("ERROR: Must put input filename on cmd line "); System.exit(0); } Scanner infile = new Scanner( new File( args[0] ) ); int[] arr = new int[INITIAL_CAPACITY]; int count= 0;
while ( infile.hasNextInt() ) { if ( count==arr.length ) arr = upSizeArr(arr); if (insertInOrder( arr, count, infile.nextInt() ) ) ++count; } arr=trimArr(arr,count); // Now count == .length printArray( arr ); // we trimmed it thus count == length so we don't bother to pass in count } // ############################################################################################################ static void printArray( int[] arr ) { for( int i=0 ; i if ( index >= 0 ) return false; boolean negative = false; for(int x = o; x < count; x++) { if(arr[x] >=newVal) { index = x; negative = true; break; } } if(negative) { for(int x = count; x > index; x--) { arr[x] = arr[x-1]; } } else { index = count; } arr [index] = newVal; return true; } arr[index] = newVal; // LEAVE THIS HERE. DO NOT REMOVE return true; } // REMOVE ALL COMMENTS FROM BSEARCH JUST BEFORE HANDIN static int bSearch(int[] a, int count, int key) { int x = 0, j= count-1; while(x <= j) { int i = x + (j-x)/2; if(k[i] == key) { return i; } if(k[i] < key) { x = i + 1; } else { j=i -1; } } return -1; } } INPUT: Expected OUtput: 15 19 32 34 38 42 46 50 57 60 65 67 71 79 85 89 90 92 98 99 100 The help is appreciated 100 89 65 46 32 90 50 38 67 71 42 92 99 57 90 89 98 34 85 19 60 15 99 79 57
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started