Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class stock{
- public stock (int[] num){
- int least = 0;
- int profit = 0;
- int index = 0;
- int end = 0;
- int x = num.length;
- for (int i=0; i <x; i ++){
- profit += num[i];
- if (least>profit){
- least=profit;
- end=i;}
- else{
- if (profit >= 0){
- profit=0;
- index= i+1;
- }}}
- System.out.print(least + " " + index + " " + end);
- }
- public static void main(String[] args){
- //insert the stock values here or change below to input statement...
- int[] w = {-9,-9,-7,6,-8,6,-7,-5,2,-6,0,-2,5,4,-5};
- stock b = new stock(w);
- }}
Advertisement
Add Comment
Please, Sign In to add comment