Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

begginner programmer. My program is done but I have a tiny issue.

$
0
0
Hi everyone,
so my program is typically done but i did it the wrong way. The way the end the loop in it is by having the user enter "-1" but the way my teacher rather have it done by using the "control d" function. How do I do that? Is it a specific code that does that? Heres how my code looks. Thanks In Advance Soo Much!!:D


public class Stocks
{
        public static void main(String[] args)
        {

                //Create Scanner object to read input prompt
                Scanner prompt = new Scanner(System.in);

                double stocks = 0;
                double min;
                double max;
                double mean;
                double sum;

                System.out.println("Enter your stock number");
                stocks = prompt.nextDouble();
                min = stocks;
                max = stocks;
                sum = stocks;
                int count = 1;

                while (stocks != -1)          
                {
                        System.out.println(" Enter your Stock Numbers, -1 will exit ");
                        stocks = prompt.nextDouble();
                        if (stocks != -1)
                        {
                                if (stocks > max)
                                        max = stocks;
                                if (stocks < min)
                                        min = stocks;
                                sum = stocks + sum;
                                count ++;
                        }
                }
                System.out.println("The mean for your stocks is: " + sum/count);
                System.out.println("The minimum for your stocks is: " + min);
                System.out.println("The maximum for your stocks is: " + max);
                System.out.println("The sum for your stocks is: " + sum);
                System.out.println("The amount of stocks calculated is: " + count);
        }
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>