My code is as follows:
import java.util.Scanner;
public class QuestionOne
{
public static void main(String[]args)
{
int numberofDays;
int sharePoints;
Scanner keyboard = new Scanner (System.in);
System.out.print("Number of days in the period: ");
numberofDays = keyboard.nextInt();
System.out.print("Share points on the first day: ");
sharePoints = keyboard.nextInt();
while (numberofDays < 10 || numberofDays > 20)
{
System.out.println("The number of days doesn’t meet the required criteria, enter it again");
System.out.print("Number of days in the period: ");
numberofDays = keyboard.nextInt();
}
System.out.println("Day " + " Share Points");
for(int i = 1; i <= numberofDays; i++)
{
if(numberofDays % 2 == 0)
if(i <= numberofDays/2)
{
sharePoints = sharePoints + 50;
System.out.println(i + " " + sharePoints);
}
else
{
sharePoints = sharePoints - 25;
System.out.println(i + " " + sharePoints);
}
else
{
if(i <= numberofDays/2 + 1)
{
sharePoints = sharePoints + 50;
System.out.println(i + " " + sharePoints);
}
else
{
sharePoints = sharePoints - 25;
System.out.println(i + " " + sharePoints);
}
}
}
}
}
This code should output to something like (as an example if the user were to enter the values 11 for the day and 550 for share price):
Day Share Points
1 550
2 600
3 650
4 700
5 750
6 800
7 775
8 750
9 725
10 700
11 675
however when I enter 11 for the day, and 550 for the share price, my code looks like:
Day Share Points
1 600
2 650
3 700
4 750
5 800
6 850
7 825
8 800
9 775
10 750
11 725
From what I can tell according to my code, I have coded it so that it adds 50 every time until the number six- whereas I want it to display the first number as the user enters it in, then to start adding and subtracting accordingly (note that everything is as I want it in my output except for the first number, and the proceeding numbers, as a result, being different). My wording may not be very accurate, but I hope the example outputs are enough to explain what I want as my output.
Aucun commentaire:
Enregistrer un commentaire