Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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: expected arr[index] = newVal; // LEAVE THIS HERE. DO NOT REMOVE ^ Project4.java:94: error: illegal start of type return true; ^ Project4.java:98: error: class, interface, or enum expected static int bSearch(int[] a, int count, int key) ^ Project4.java:101: error: class, interface, or enum expected while(x <= j) ^ Project4.java:105: error: class, interface, or enum expected if(k[i] == key) ^ Project4.java:108: error: class, interface, or enum expected } ^ Project4.java:112: error: class, interface, or enum expected } ^ Project4.java:116: error: class, interface, or enum expected } ^ Project4.java:119: error: class, interface, or enum expected } ^ 11 errors

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:

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions