Function

import java.util.Scanner;


public class Sample


 { 

 

void display (int a) 

 System.out.println("My age is"+ " "+a);

}   

 

void print1(String s) 

  System.out.println("My name is"+ " " +s);


void show(int a, String s) 

System.out.println("this is "+ s + " " +"My age is" +" " +a);



public static void main(String args[]) 


  { 

    int choice; 

    int age=21; 

   String name="Chitransh"; 

  

   System.out.println("Enter your choice");

   Scanner s1= new Scanner(System.in);  

   Sample sm = new Sample(); 

   

   choice= s1.nextInt(); 

   

   switch(choice) 

   

   {  

   

        //displaying age.

   

   case 1: sm.display(age); 

                break; 

  

       // displaying name.    

  

   case 2: sm.print1(name); 

                 break; 

     

        //displaying both   

  

   case 3:  sm.show(21,"Chitransh"); 

                  break; 

           

   

   default: System.out.println("Invalid choice"); 

   

   }

    

  }




 }

  

  

   

  

Comments