150k views
0 votes
Beginners’ computer science!

Language- Java

Details of assignment-

3) As a coder at a pharmaceutical company,
you've been tasked with writing a program that will determine how long a particular drug may stay on shelves to be sold in
stores. Assume this drug loses 12% of its effectiveness every month (save into a
variable, but you don't have to get this value from the keyboard), and must be
discarded when effectiveness dips below 50%. Write a program that prints how many months the drug can remain on
shelves.

Please leave a comment if you would like a sample run!

User Neminem
by
6.0k points

1 Answer

6 votes

Answer:

public class Drug {

public static void main(String[] args) {

int effectiveness = 100;

int months = 0;

while (effectiveness > 50) {

effectiveness *= 0.88;

months += 1;

}

System.out.println("The drug can remain on shelves for " + months + " months");

}

}

please let me know if this is correct! :D

User Manak Kapoor
by
6.2k points