Please help me ONLY for the second method : public static int[] runningGroups(String[] inputFileNames) throws IOException.
The second method has an "array of files as a parameter". and return int [ ]. Each element of the return array is the number of group that can get from the first method.
I got an error Exception in thread "main" java.lang.NullPointerException
Here my code:
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class RunningGroups {
public static void main(String[] args) throws IOException
{
String file = args[0];
System.out.print(" Total : ");
System.out.print(runningGroups(file));
String[] test = new String[5];
String t1 = args[1] ;
String t2 = args[2] ;
String t3 = args[3] ;
String t4 = args[4];
test[0] = t1;
test[1] = t2;
test[2] = t3;
test[3] = t4;
int[] result
= new int[test.length];
result =
runningGroups(test);
System.out.println("Test array");
for(int i=0; i<result.length; i++){
System.out.print(result[i] + " ");
}
}
public static int runningGroups(String inputFileName) throws
IOException{
Scanner input = new Scanner(new
File(inputFileName));
String str = "";
while(input.hasNext()) {
str = str + input.next() + " ";
}
String[] temp = str.split(" ");
int n = Integer.parseInt(temp[0]);
int[] start = new int[n];
int[] speed = new int[n];
int l = 0,k = 0;
ArrayList<Integer> min_speed_pos =
new ArrayList<Integer>();
int j = 0;
int min_speed =
1000000;
for(int i = 1; i<temp.length; i = i+2)
{
start[l] =
Integer.parseInt(temp[i]);
l++;
}
for(int i = 2; i<temp.length; i= i+2)
{
speed[k] =
Integer.parseInt(temp[i]);
min_speed = Math.min(min_speed,
speed[k]);
k++;
}
for(int i = 0; i<n;
i++){
if(speed[i]
== min_speed)
min_speed_pos.add(i);
}
return
min_speed_pos.size();
}
public static int[] runningGroups(String[] inputFileName) throws
IOException{
int[] groups = new int[inputFileName.length];
for(int i =0; i< inputFileName.length; i++){
String temp = inputFileName[i];
groups[i] = runningGroups(temp);
}
return groups;
}
}
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Please help me ONLY for the second method : public static int[] runningGroups(String[] inputFileNames) throws IOException....
Draw a flowchart for this program public class InsertionSort { public static void main(String a[]) { int[] array = {7, 1, 3, 2, 42, 76, 9}; insertionSort(array); } public static int[] insertionSort(int[] input) { int temp; for (int i = 1; i < input.length; i++) { for (int j = i; j > 0; j--) { if (input[j] < input[j - 1]) { temp = input[j]; input[j] = input[j - 1]; input[j - 1] = temp; } } display(input, i);...
public static int countCharacter(String str, char c) { // This recursive method takes a String and a char as parameters and // returns the number of times the char appears in the String. You may // use the function charAt(int i) described below to test if a single // character of the input String matches the input char. // For example, countCharacter(“bobbie”, ‘b’) would return back 3, while // countCharacter(“xyzzy”, ‘y’) would return back 2. // Must be a RECURSIVE...
Trying to practice this assignment Argument list: the *yahoonews.txt Data file: yahoonews.txt Write a program named WordCount.java, in this program, implement two static methods as specified below: public static int countWord(Sting word, String str) this method counts the number of occurrence of the word in the String (str) public static int countWord(String word, File file) This method counts the number of occurrence of the word in the file. Ignore case in the word. Possible punctuation and symbals in the file...
the question, this is not running it throws an exception would you help me it is a java program // why this is not running would you help me public class sample { public static void main(String[] args){ String str[][] = new String[10]['K']; for(int i= 1;i<=10; i++){ for(char j= 'A';j<='J'; j++){ System.out.print(i +" "+ j); str[i][j] = "A"; System.out.print(" "); } System.out.println(); } ...
What is printed by running the following code? public static void main(String[] args) { int[] nums = {2, 3, 4}; int n = 5; changeMe1(n, nums); System.out.print( n ); System.out.print(nums[0]); changeMe2(n, nums); System.out.print( n ); System.out.print(nums[0]); } public static void changeMe1(int number, int[] list) { number++; list[0]++; } public static void changeMe2(int number, int[] list) { number = 9; list = new int[1]; list[0] = 99; }
package array; public class Test { static int[] data = (0,1,2,3,4,5,6,7,8); public static void main (String[] a) { for ( int i = 0;i<data.length; i++) { if(i %3 == 0) { System.out.print("A"); System.out.print(data[i]); System.out.print(" "); } } I need an explanation of what this code is doing ? is there anything wrong with it }}
Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 { public static void main(String[] args)throws IOException{ File prg8 = new File("program8.txt"); Scanner reader = new Scanner(prg8); String cName = ""; int cID = 0; double bill = 0.0; String email = ""; double nExempt = 0.0; String tExempt = ""; int x = 0; int j = 1; while(reader.hasNextInt()) { x = reader.nextInt();} Customers c1 [] = new Customers [x]; for (int...
Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class Car { private int year; private String model; private String make; int speed; public Car(int year, String model, String make, int speed) { this.year = year; this.model = model; this.make = make; this.speed = speed; } public Car() { } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getModel() { return model; }...
You will implement the following method public static int[] linearSearchExtended(int[][] numbers, int key) { // Implement this method return new int[] {}; } There is a utility method provided for you with the following signature. You may use this method to convert a list of integers into an array. public static int[] convertIntegers(List<Integer> integers) Provided code import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Scanner; public class MatrixSearch { // This method converts a list of integers to an array...
public class Test { private static int i =0; private static int j =0; public static void main(String[] args) { int i = 2; int k = 3; { int j =3; System.out.println("i + j is : " + i + j); } k = i + j; System.out.println("K is " + k ); System.out.println("K is " + j); } } why is the output i + j = 23 K =2 K =0 Please explain a step by step...