Question: Assignment4_1.java as the file name and Assignment4_1 as the class name - Write a console program with a static method printHello() (in addition to main()

Assignment4_1.java as the file name and Assignment4_1 as the class name - Write a console program with a static method printHello() (in addition to main() method which is also static) that prints out "Hello World". Call that method from main().

Assignment4_2.java as the file name and Assignment4_2 as the class name - Write a console program with static method inc() that takes value of type int and returns that value increased by one. In main() method do the following:

Ask a user to enter an integer value

Call method inc() and pass user input (integer value) into that method

Print returned result

Assignment4_3.java as the file name and Assignment4_3 as the class name - Write a console program with static method inc() that takes value of type int and returns that value increased by one. In main() - public static void localModification(int a) { a++; } Call that method from main() while passing some integer value stored in a variable, for instance: public static void main(String[] args) { int A = 5; localModification(A); System.out.println(A); } Make sure that value of A, printed in main(), is not affected by local modification made within the localModification() method, i.e. value 5 is printed. Try to understand why. Task: Change declaration and/or implementation and/or call of the localModification()method, such that print statement in main() method prints incremented value, i.e. 6.

Important Notes

Remember, you will need to put the keyword static before each method you write, because we aren't doing OOP yet!

When you create a method you should always define what it takes as parameters and what it returns as a result. Method parameters can be considered from two perspectives:

in method declaration they are called formal parameters

when you use (call) the method, they are called actual parameters.

Result can either be of type void (nothing is expected to be returned upon completion of the method) or some other data type declared in method signature.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!