Answer:
Following are the code to this question:
public class Main//defining a class
{
public static String yearsToVote(int age)//defining a method yearsToVote that holds an integer variable as a parameter
{
String s;//defining a String variable
int a;//defining a integer variable
if(age<18)//defining if block to check age
{
a=18-age;//calculating the age value
s="The Person has to wait "+a+ " more years before they can vote";//print string value with age
}
else//defining else variable
{
a=age-18;//calculating age value
s="Since last " +a+" years person has been abel to vote ";//print string value with age
}
return s; // return String value
}
public static void main(String[] args)//defining a mein method
{
int age=22;//defining an integer variable with value
System.out.println(yearsToVote(22));//use print method to call static method
}
}
Output:
Since last 4 years person has been abel to vote
Step-by-step explanation:
In this code, a static method "yearsToVote" is declared that accepts an integer variable "age" in its parameter, and defined one string and one integer variable, and use if block to check value and return string value with a message.
In the next step, the main method is declared, which defines an integer variable and holds its value and passes into the method "yearsToVote" use the print method to call and print its value.