Wednesday, 10 July 2013

Java Program Using Methods to display name

Program:


import java.util.*;
class cls1{
public void show(String name)
{
System.out.println("hello  "+name);
}
}
class apple
{
public static void main(String[] args)
{
 Scanner input=new Scanner(System.in);
cls1 c=new cls1();
System.out.println("enter your name:");
String name=input.nextLine();
c.show(name);
}
}

 Output:
enter your name: vegeta!

hello vegeta!

Note:
In this program when you enter your name
by using scanner class
then it will stores the string in "name"
we had created class cls1 having method
show(name)

so,your entered name is stored in that method
So,as a result it will displayed along with hello

No comments:

Post a Comment