83.9k views
1 vote
Write a method takeAwalk which will take an argument saying how many spare minutes you have for your walk (a whole number), and will print out where you will go using System.out.println. If you have at least 60 minutes for your walk, you will go to the store: print "Store". Otherwise, if you have at least 10 minutes, you will walk around the block: print "Block". Otherwise, print "Nowhere". The method does not return any value. 1

User Stloc
by
5.3k points

1 Answer

4 votes

Answer:

public class walk {

//create the function

public static void takeAwalk(int spare_Minute) {

//check the condition and print if match

if(spare_Minute>=60) {

System.out.println("Store");

}else if(spare_Minute>=10) {

System.out.println("Block");

}else {

System.out.println("Nowhere");

}

public static void main(String[] args) {

//call the function

takeAwalk(60);

}

}

Step-by-step explanation:

Create the class and define the function takeAwalk which takes one parameter of integer type and the function return type is void. It means the function does not return any value.

In the function, take the continuous if-else statement.

syntax:

if(condition){

statement;

}else if(condition){

statement;

}else{

statement;

}

it takes the condition, if the condition is true then execute the statement otherwise program move to the else if() part. if this is also false then the program moves to the else part.

create the main function for testing the program and call the function.

suppose the value pass is 60.

then, program control moves to the function definition and start executing.

if-else statement checks the condition, 60 >= 60 condition match and the program print the message "Store".

User Udhay Titus
by
5.3k points