Create a reusable piece of code that will print name of the user. Depending on the input value, the
output should vary. Hint-Create method (Reusable Code you see!) Do this in 2 ways using Void return
type and create an
...
Create a reusable piece of code that will print name of the user. Depending on the input value, the
output should vary. Hint-Create method (Reusable Code you see!) Do this in 2 ways using Void return
type and create another program to create a method SampleOutput with String return type. ▪You
have entered your name as Ram▪You have entered your name as Sham▪You have entered your name
as Steve▪You have entered your name as Tim
public class MyClass {
static void myMethod(String name) {
Scanner myObj1 = new Scanner(System.in); // Create a Scanner object
System.out.println("You have entered your name as Ram ");
Scanner myObj2 = new Scanner(System.in); // Create a Scanner object
System.out.println("You have entered your name as Sham");
Scanner myObj3 = new Scanner(System.in); // Create a Scanner object
System.out.println("You have entered your name as Steve");
Scanner myObj4 = new Scanner(System.in); // Create a Scanner object
System.out.println("You have entered your name as Tim");
}
public static void main(String[] args) {
myMethod("myobj1”);
myMethod("myobj2”);
myMethod("myobj3”);
}
}public class MyClass
{
static string myMethod(str1, str2, str3)
{
return str1,str2,str3;
Scanner myObj1 = new Scanner(System.in); // Create a Scanner object
System.out.println("You have entered your name as Ram ");
Scanner myObj2 = new Scanner(System.in); // Create a Scanner object
System.out.println("You have entered your name as Sham");
Scanner myObj3 = new Scanner(System.in); // Create a Scanner object
System.out.println("You have entered your name as Steve");
Scanner myObj4 = new Scanner(System.in); // Create a Scanner object
System.out.println("You have entered your name as Tim");
}
}
public static void main(String[] args) {
System.out.println(SampleOutput(myobj1,myobj2,myobj3));
}
}
Create a program to take input from user to enter a number between 1 to 12. If a number is entered,
print the corresponding name of the month. For E.g. ▪If user enters '1' January should be printed.▪If
user enters '3' March should be printed. ▪If user enters '12' December should be printedimport java.util.Scanner;
public class SwitchBasedSolution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter month's number: ");
int monthNumber;
monthNumber = in.nextInt();
switch (monthNumber) {
[Show More]