Professional Documents
Culture Documents
home / study / engineering / computer science / computer science questions and answers / solve in java starter code import java.io.*; import java.mat…
Continue to post
0 questions remaining
888-888-8888 Text me
My Textbook Solutions
Starter code
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
class Result {
/*
* 1. INTEGER_ARRAY stockPrices
* 2. INTEGER k
*/
public static int
countHighlyProfitableMonths(List<Integer> stockPrices, int k)
{
}
}
public class Solution {
int stockPricesItem =
Integer.parseInt(bufferedReader.readLine().trim());
stockPrices.add(stockPricesItem);
}
int k = Integer.parseInt(bufferedReader.readLine().trim());
int result = Result.countHighlyProfitableMonths(stockPrices,
k);
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
Starter input:
EXAMPLE 1:
8
12
2
EXAMPLE 2:
4
4
EXAMPLE 3:
6
3
Show transcribed image text
Expert Answer
CODE
SCREENSHOTS:
SOLUTION 1:
SOLUTION 2:
CODE:
SOLUTION 1:
import java.io.*;
import java.util.*;
class Result {
/*
*
*/
// Check if price at j is greater than
priceToCompare
if (stockPrices.get(j) > priceToCompare)
{
// Set priceToCompare to
price at j
priceToCompare =
stockPrices.get(j);
} else
kProfitableMnthsFound =
false;
}
if
(kProfitableMnthsFound)
grpCount += 1; // Increment grpCount by 1
}
}
stockPrices.add(stockPricesItem);
}
int k =
Integer.parseInt(bufferedReader.readLine().trim());
// profitable
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
SOLUTION 2:
import java.io.*;
import java.util.*;
class Result {
/*
*
*/
if
(stockPrices.get(i) <= stockPrices.get(i - 1)) {
// Set mismatchIdx to i
mismatchIdx = i;
}
profitableGrpCount += 1; // Increment
profitableGrpCount by 1
}
// Return
profitableGrpCount
}
stockPrices.add(stockPricesItem);
}
int k =
Integer.parseInt(bufferedReader.readLine().trim());
// profitable
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
SAMPLE
OUTPUT:
Sample Output 1
Sample Output 2
Sample Output 3
Sample Output 4
LOGIC
For example,
if n = 6
stockPrices = {1, 2, 3, 3, 4, 5}
k=3
Group 1 - 1, 2, 3
Group 2 - 2, 3, 3
Group 3 - 3, 3, 4
Group 4 - 3, 4, 5
Q: Solve in Java
Starter code:
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
class Result {
/*
* Complete the 'getUnallottedUsers' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts following parameters:
* 1.
2D_INTEGER_ARRAY...
A: See answer
A: See answer
Show more
COMPANY LEGAL & POLICIES CHEGG PRODUCTS AND SERVICES CHEGG NETWORK CUSTOMER SERVICE
About Chegg Advertising Choices Cheap Textbooks Mobile Apps EasyBib Customer Service
Chegg For Good Cookie Notice Chegg Coupon Sell Textbooks Internships.com Give Us Feedback
College Marketing General Policies Chegg Play Solutions Manual Thinkful Help with eTextbooks
Corporate Development Intellectual Property Rights Chegg Study Help Study 101 Help to use EasyBib Plus
Investor Relations Terms of Use College Textbooks Textbook Rental Manage Chegg Study
Jobs Global Privacy Policy eTextbooks Used Textbooks Subscription
Join Our Affiliate Program DO NOT SELL MY INFO Flashcards Digital Access Codes Return Your Books
Media Center Honor Code Learn Chegg Money Textbook Return Policy