Answer to Question #266078 in Java | JSP | JSF for shweta

Question #266078

Zombie Apocalypse


A patient with first stage zombie virus has escaped from the facility in a city of population N. The zombie virus is very dangerous as it passer on to other people as they come in contact with the patient making them a patient as well.


Zombie virus has K life stages to develop, each of which takes 1 unit of time. Only the last stage is contagious. A person with zombie virus attacks only healthy people and can only affect one person in 1 unit of time.


if the patient escaped on Day 1. Find out the number of days it will take to wipe out the entire city's healthy population and turn them into a last stage zombie.

Note: 1 unit of time is equal to 1 day.


Input Specification.


Input1:Total healthy population of the city.

input2:Number of stages of zombie virus.


Output Specification

your function must return the numbers of days.

Example 1:

input1:10

input2:1

output:5





please give java code for this question.


1
Expert's answer
2021-11-14T17:02:07-0500
public class Solution {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int input1 = s.nextInt();
    int input2 = s.nextInt();
    int ans = 0;
    while (input1 > input2) {
      input2 *= 2;
      ans++;
    }
    System.out.println(ans + 1);
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS