Write a program that uses a static method called printMessage that takes a string and an integer as parameters. The string and integer parameters represent a person’s name and age. When printMessage is called with arguments “Joan” and 18, the method prints “Joan, you are 18 years old”.
Sample output:
Enter your name: Joan
Enter your age: 18
Joan, you are 18 years old
import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = in.nextLine();
System.out.print("Enter your age: ");
int age = in.nextInt();
printMessage(name, age);
in.close();
}
static void printMessage(String name, int age) {
System.out.println(name + ", you are " + age + " years old");
}
}
Comments
Leave a comment