Answer to Question #323982 in Java | JSP | JSF for stephanie

Question #323982

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




1
Expert's answer
2022-04-05T15:30:16-0400


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");
	}


}

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