1
0
Fork 0

update format

This commit is contained in:
Justin Parsell 2021-12-01 01:48:02 -05:00
parent cb49e2b00d
commit a92879c27b
2 changed files with 10 additions and 6 deletions

View File

@ -3,36 +3,40 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
import org.json.JSONArray; import org.json.JSONArray; //requires external "org.json"
import org.json.JSONTokener; import org.json.JSONTokener; //requires external "org.json"
class increaseCounter{ class increaseCounter{
public static void main(String[] args){ public static void main(String[] args){
File input = new File("input.json"); File input = new File("input.json");
try{ try{
// Get the file, into an inputstream, and give it to json tokenizer
InputStream fileIn = new FileInputStream(input); InputStream fileIn = new FileInputStream(input);
JSONTokener inputJson = new JSONTokener(fileIn); JSONTokener inputJson = new JSONTokener(fileIn);
// get the only object, which is a jsonarray
JSONArray values = (JSONArray)inputJson.nextValue(); JSONArray values = (JSONArray)inputJson.nextValue();
//System.out.println(inputArray.toString()); //System.out.println(inputArray.toString());
// Get the amount of times it increases // Get the amount of times it increases
int increaseCount = 0; int increaseCount = 0;
for(int i = 1; i < values.length(); i++) for(int i = 1; i < values.length(); i++)
if(values.getInt(i-1) < values.getInt(i)) if(values.getInt(i-1) < values.getInt(i)) // if array[i-1] is less then array[i]
increaseCount++; increaseCount++;
System.out.println(increaseCount); System.out.println(increaseCount);
// Get the amount of times it increase by three-measure sliding increments // Get the amount of times it increase by three-measure sliding increments
int increaseCount3 = 0; int increaseCount3 = 0;
for(int i = 3; i < values.length(); i++){ for(int i = 3; i < values.length(); i++){
int winA = values.getInt(i - 3) + values.getInt(i - 2) + values.getInt(i - 1); int winA = values.getInt(i - 3) + values.getInt(i - 2) + values.getInt(i - 1); // get array[i-3] + array[i-2] + array[i-1] = "a" window
int winB = values.getInt(i - 2) + values.getInt(i - 1) + values.getInt(i); int winB = values.getInt(i - 2) + values.getInt(i - 1) + values.getInt(i); // get array[i-2] + array [i-1] + array[i] = "b" window
if(winA < winB) if(winA < winB)
increaseCount3++; increaseCount3++;
} }
System.out.println(increaseCount3); System.out.println(increaseCount3);
} catch(FileNotFoundException e){ } catch(FileNotFoundException e){
e.printStackTrace(); e.printStackTrace();
} }