[Java]
/*
* Start the program header annotation.
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: determines the number entered
* Author: Xue Guangchen
* Completion date: January 1, September 15, 2011
* Version No.: x1.0
* Description of tasks and Solutions
* Input description:
* Problem description: enter a number and use the if statement to determine the matching number.
If you enter:
1>. Print: The number you entered is 1
2>. Print: The number you entered is 2
3>. Print: The number you entered is 3
Other numbers printed: Invalid numbers entered
Note: Use the if-else and switch methods.
* Program output:
* End the comment in the program Header
*/
Package xue.com;
Public class If_Switch {
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
System. out. println ("enter a number :");
Int number = Console. readInt ();
Output_If (number );
System. out. println ();
Output_Switch (number );
}
Public static void output_If (int I ){
System. out. println ("output with if statement ");
If (I = 1)
{
System. out. println ("the number you entered is 1 ");
}
Else if (I = 2)
{
System. out. println ("the number you entered is 2 ");
}
Else if (I = 3)
{
System. out. println ("the number you entered is 3 ");
}
Else
{
System. out. println ("invalid number entered ");
}
}
Public static void output_Switch (int I ){
System. out. println ("output with switch statement ");
Switch (I)
{
Case 1: System. out. println ("the number you entered is 1"); break;
Case 2: System. out. println ("the number you entered is 2"); break;
Case 3: System. out. println ("the number you entered is 3"); break;
Default: System. out. println ("invalid number entered ");
}
}
} Www.2cto.com
Running result:
Enter a number:
3
Output with if statement
The number you entered is 3.
Output with switch statement
The number you entered is 3.