简体   繁体   中英

Passing value from one void function to another void function in java

I am a student of class XI am doing a school project in java. I got stuck here somewhere. My Code is as follow.

package school.PRo;
    import java.util.Scanner;
    class Telephone_Bill
       {
           String c_name[]=new String[10];
           String c_add[]=new String[10];
           String phno[]=new String[10];
           void accept(int n)
                {
                     Telephone_Bill ob=new Telephone_Bill();
                    Scanner in=new Scanner(System.in);
                      int i;
                     String name[]=new String[10];
                     String add[]=new String[10];
                     String ph[]=new String[10];
                     for(i=0;i<n;i++)
                        {
                            System.out.println("Index Number:>>"+i+1);
                            System.out.print("Enter The name of the customer:>>");
                            name[i]=in.nextLine();
                            c_name[i]=name[i];
                            System.out.print("Enter The address of the customer:>>");
                            add[i]=in.nextLine();
                            c_add[i]=add[i];
                            System.out.print("Enter The phone number of the customer:>>");
                            ph[i]=in.nextLine();
                            phno[i]=ph[i];
                        }
                        ob.show(n);
                    }
                    static void main(String args[])
                        {
                            int n;
                            Scanner in=new Scanner(System.in);
                            Telephone_Bill ob=new Telephone_Bill();
                            System.out.print("Enter the no. of customer:>");
                            n=in.nextInt();
                            ob.accept(n);
                        }
                    void show()
                        {
                            int i=0,p;
                            while(i<p)
                                {
                                    System.out.print(c_name[i]+" "+c_add[i]+" "+phno[i]);
                                }
                            }
                        }

What I am facing problem is that when I am passing the value from function void accept() to function void show() I cannot pass that value from one void function to another void function. Something I am going wrong. So, I want to know how can I pass the value from one void function to another void function. Please help me to get rid from here. Thanks in advance.

您需要向show()方法添加一个参数。

void show(int p) {

when you pass an argument to a function, that function declaration should have an argument which can actually accept it. You are missing it here

void show() {
}

When you change you method show to

void show(int arg)

now your method show can receive and argument in the variable arg

void states that, the method show doesn't return anything. It doesn't have anything to do with what argument is passed.

Read this for more info

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM