ifelse exercise 3

The age of a dog is equivalent to 10.5 years of a person in the first two years, and every year thereafter is equivalent to a person’s four years old. Write a program to input the age of the dog and output the equivalent of the age of a person.

package javaexer;
import java.util.Scanner;
public class ifexer3 {   public static void main(String[] agr) {       Scanner scanner=new Scanner(System.in);       System.out.println("Please enter the age of the dog:" );       double age=scanner.nextDouble();       if(age<=2) {           System.out.println("The age of a dog is equivalent to that of a person"+age*10.5+"age");       }       else {           System.out .println("The age of a dog is equivalent to that of a person"+(2*10.5+(age-2)*4)+"years old");       }   } }










      

Guess you like

Origin blog.csdn.net/tdongmu/article/details/108139007