Respuesta :
Following are the program to the given question:
import java.util.Scanner;//import package
import java.util.InputMismatchException;//import package
public class NameAgeChecker //defining a class NameAgeChecker
{
public static void main(String[] axc)//defining main method
{
String inputName;//defining string variable
int age;//defining integer variable
Scanner sehr = new Scanner(System.in);//creating Scanner class object
inputName = sehr.next();//input string value
while (!(inputName.equals("-1"))) //use while loop that check string value
{
try//defining a try block
{
age = sehr.nextInt();//use integer variable that input value
}
catch (InputMismatchException e)//defining catch block
{
age = -1;//use age variable that hold negative value
sehr.nextLine();//input value
}
System.out.println(inputName + " " + (age + 1));//print value
inputName = sehr.next();//input string value
}
}
}
Output:
please find the output in the attached file.
Explanation:
- Importing the packages.
- Defining the main class "NameAgeChecker".
- Inside the class define the main method, and the method one string and one integer variable "inputName, age" is declared.
- Use a while loop that takes value from user-input from the user until the user enters -1.
- In addition to printing the name and the incremented age, it will also print the name and the input's age.
- If the second phase of the line is entered as a string, the software will print age as 0.
Learn more:
Program: brainly.com/question/2266606