Method overload programming problem, can be used as reference __ programming

Source: Internet
Author: User
Using the method overload method to reuse code to complete the following functions
1. Define methods for getting console input integers
Return value: The integer entered
2. Define get console input integer, method with specified hint
Parameters: Prompt Content
Return value: The integer entered
3. Defines a method for obtaining a console input integer, with a specified hint, with a specified range (between the minimum and maximum values),
Method must return the input integer between the minimum and maximum values
Parameters: Hint content, range minimum, range maximum
Return value: The integer entered

4 test the above method in Main method

Import Java.util.Scanner;
public class test1{public
	static void Main (String args[]) {
		int max=50;
		SYSTEM.OUT.PRINTLN ("Input 20-50 Integer:" +inputint ("Input 20-50 integer", 20,50));
	}
	public static int Inputint () {
		String defaulttishi= "Please enter int integer";
		int In=inputint (Defaulttishi);
		return in;
	}
	public static int Inputint (String tisi) {
		Scanner sc=new Scanner (system.in);
		System.out.println (Tisi);
		int In=sc.nextint ();
		return in;
	}
	public static int Inputint (String tisi,int min,int max) {while
		(true) {
			int in=inputint (tisi);
			if (In>=min&&in<=max) {return in
				;
			}
		}
	}


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.