[英]Passing value from one void function to another void function in java
我是XI班的學生,正在用Java做一個學校項目。 我被困在這里的某個地方。 我的代碼如下。
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]);
}
}
}
我面臨的問題是,當我將值從函數void accept()傳遞給函數void show()時,我無法將該值從一個void函數傳遞給另一個void函數。 我出了點問題。 因此,我想知道如何將值從一個void函數傳遞給另一個void函數。 請幫助我擺脫這里。 提前致謝。
您需要向show()方法添加一個參數。
void show(int p) {
當您將參數傳遞給函數時,該函數聲明應具有一個實際上可以接受它的參數。 你在這里想念它
void show() {
}
更改時,方法顯示為
void show(int arg)
現在您的方法show可以接收變量arg中的參數了
void指出,方法show不返回任何內容。 它與傳遞的參數無關。
閱讀此以獲得更多信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.