We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
import java .util.Scanner;
public class trade {
public static void main(String argsp[])
{
Scanner scan=new Scanner(System.in);
int n;
n=scan.nextInt();
int price[]=new int[n];
int days[]=new int[n];
for(int i=0;i<n;i++)
{
price[i]=scan.nextInt();
int j=i;
days[i]=++j;
}
for(int i=0;i<n;i++)
{
System.out.print( price[i] +" ");
// System.out.print(days[i]);
}
System.out.println();
//minimum value to find out
int min=price[0];
int day=0;
int max=price[0];
for(int i =1;i<n;i++)
{
if(min>price[i])
{
min=price[i];
day=i;
}
if(max<price[i])
{
max=price[i];
}
}
System.out.println(" trade price "+" "+min +" buy on date"+" "+ (day+1));
System.out.println(" trade price while selling it"+" "
+ " sold on this day"+ (day+1));
int profit=max-min;
if(profit>0)
{
System.out.println(" seller found their profit"+ " = "+profit);
}
else if(profit<=0 )
{
System.out.println(" trader is in loss");
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Sort
You are viewing a single comment's thread. Return to all comments →
using java 7
import java .util.Scanner; public class trade { public static void main(String argsp[]) { Scanner scan=new Scanner(System.in); int n; n=scan.nextInt(); int price[]=new int[n]; int days[]=new int[n];
}