Java Practice (Enter a number, use the IF statement to determine the number of matches)

Source: Internet
Author: User
Tags readline
/* (start of program header comment) * Copyright and Version Statement of program (c) 2011, student of Computer College of Yantai University * All rights reserved. * File Name: * Author: Shangpeng * Date of Completion: September 15, 2012 * Version number: 001 * Description of task and solution * Input description
: * Problem Description: Enter a number and use the IF statement to determine the matching number. If the input is: 1> Print: The number you entered is 1 2>. Print: The number you entered is 2 3>.

Print: You entered the digital 3 other digital printing: entered the nonstandard number note: The use of if-else and switch two ways to achieve respectively. * Program Output: * Program Header comment End/public class Test3 {/** * @param args/public static void main (string[] args) {Syste
		M.out.println ("Please enter a number:");
		String str1= console.readline ();
		
		int x = Integer.parseint (STR1);
			if (x = = 1) System.out.println ("The number you enter is 1");
		      if (x ==2) System.out.println ("The number you enter is 2");
				if (x = = 3) System.out.println ("The number you enter is 3");
					
				
				
				
				
			
		
	if (x!=1 &&x!= 2&&x!=3) System.out.println ("You have entered a number that does not conform to the specification"); }

}
public class Test3 {

	/**
	 * @param args
	 *
	/public static void main (string[] args) {
		System.out.println ("Please enter a number:");
		String str1= console.readline ();
		int x = Integer.parseint (str1);
		
		Switch (x)
		{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 ("The number you entered does not conform to spec:");}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.