Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to write this code, but it won\'t let me because I didn\'t start at

ID: 663000 • Letter: I

Question


I am trying to write this code, but it won't let me because I didn't start at main. I just created my own method named zool. Please help! Exercise 3.3. The point of this exercise is to make sure you understand how to write and invoke methods that take parameters 1. Write the first line of a method named zool that takes three parame- ters: an int and two Strings. 2. Write a line of code that invokes zool, passing as arguments the value 11, the name of your first pet, and the name of the street you grew up on

Explanation / Answer

1.Here,we need to create a method called zoo1,whuich take three parameters one is interger and two String variables.and we need to call that method with proper arguments passed to it.hence,for the first part I wrote the function and displays the parameters which are sent by called function to calling function.

2.For the second, to invokes the function we need to create main function to call the function.

function definition is as follows:static void zoo1(int no,String petname,String street neme);

Here,'static' is for invoking the method without object of the class and 'void' tell about the function returns nothing.

Program:

/*import statements*/

import java.lang.*;

class ParamDemo

{

static void zoo1(int no,String petname,String streetname)

{

System.out.println("serial number is:"+no);

System.out.println("petname is "+petname);

System.out.println(Street name is "+streetname);

}//end of zoo1

public static void main(String args[])

{

int no=11;

String petname="puppy";

String Streetname="gandhi nagar";

zoo1(no,petname,streetname);

/*We can set different variable names in main and zoo1 method.also there is no ambiguity in having same names in calling function(is nothing but main()) and called function(is nothing but zoo1).According to variable scope,the local variable scope is within the function on ly.Hence no problem.*/

}//end of main

}

Output:

Serial number:11

PetName:puppy

streetname:gandhi nagar

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote