Results 1 to 1 of 1
  1. #1
    rice's Avatar
    rice is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default More than one input in one private method

    Java Code:
    import java.util.Scanner;
    public class TryClass
    
    {
    	public static void main(String[] args)
    	{
    	Scanner keyboard = new Scanner(System.in);
    	GetInt(keyboard, "Integer", 1, 100);
    	GetDouble(keyboard, "Double", 0.1, 100);
    	}
    
    	private static int GetInt(Scanner inStream, String prompt, int minValue, int maxValue)
    	{
    		System.out.print(prompt + ">> ");
    		int value = inStream.nextInt();
    
    		while (value <= 1 || value >= 100)
    		{
    			if (value <= 1 || value >= 100)
    		{
    			System.out.println("*** Value must be between 1 and 100");
    		}
    		System.out.print(prompt + ">> ");
    		value = inStream.nextInt();
    
    		}
    		
    		return value;
    	}
    
    }
    I would like to ask whether it's possible to write in another input/scanner code inside that private method? And that input will also have another loop, exactly like the one displayed.


    Hehe, just figured another way to do it.
    Last edited by rice; 10-02-2009 at 08:23 AM. Reason: Figured it out

Similar Threads

  1. Private constructor and super()
    By Basit56 in forum Advanced Java
    Replies: 9
    Last Post: 08-21-2009, 06:19 AM
  2. Is it acceptable to use a private object?
    By saul_2110 in forum New To Java
    Replies: 8
    Last Post: 12-08-2008, 06:04 PM
  3. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM
  4. Private main method
    By bugger in forum New To Java
    Replies: 1
    Last Post: 12-21-2007, 09:45 AM
  5. Question of private member
    By Felissa in forum Advanced Java
    Replies: 2
    Last Post: 06-28-2007, 09:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •