以下是从键盘输入的,你可以把代码直接拷贝过去就可以运行。import java.io.*; public class test { public static void main(String[] args) throws IOException { InputStreamReader reader = new InputStreamReader(System.in); BufferedReader input = new BufferedReader(reader); System.out.print("Enter your name: "); String name = input.readLine(); test.sayHello(name); }
public static void sayHello(String name) { System.out.println("hello,"+name+"!"); } }
以下这个是直接在程序中传入参数 import java.io.*; public class test { public static void main(String[] args) throws IOException { String name = "world"; test.sayHello(name); }
public static void sayHello(String name) { System.out.println("hello,"+name+"!"); } }
public class test
{
public static void main(String[] args) throws IOException
{
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("Enter your name: ");
String name = input.readLine();
test.sayHello(name);
}
public static void sayHello(String name)
{
System.out.println("hello,"+name+"!");
}
}
import java.io.*;
public class test
{
public static void main(String[] args) throws IOException
{
String name = "world";
test.sayHello(name);
}
public static void sayHello(String name)
{
System.out.println("hello,"+name+"!");
}
}