Q:

Can you return a string from a while loop without using the return command?

I am learning java in the internet in sites like "oracle academy" and using Google to search how to do somethings, i wanted to make a simple java program that takes an number(day) a number or word(month) and another number(year), so if you input something like 
"3" "1" and "1993"  

it outputs  
"January 1st, 1993"  

and if you input something like  
"2" "July" and "1992"  

it outputs   
"7/2/1992"  

I kind of already know how to make it using "case" and while loops to tell you if you input something incorrectly, but on the "day" part i tried using a while loop to keep asking you to input something if the input wasn't a number between 1 and 31 but i can't make it return the number from the while loop using the return command, is there any way to return the number without using the return command or not?
the code:
public static void main(String[] args) {  
    String x;  
    Scanner scan = new Scanner(System.in);  
        //day  
        System.out.println("Insert Day");  
        while (1 < 2){  
        x = scan.nextLine();  
        if (x.matches(".*\\d.*")){  
            q = Integer.parseInt(x);  
            if ((0 < q) && (q < 32)){  
                return q;  
        }  
            else {  
            System.out.println("please use a valid number");       
        }  
        }  
        else {  
            System.out.println("please use a number");  
        }  
        }  
        System.out.println(q);  

A:

You can use return if you refactor this into a separate function:
public static int getDay() {
    Scanner scan = new Scanner(System.in);
    System.out.println("Insert Day");
    while (true){  
        line = scan.nextLine();  
        if (line.matches(".*\\d.*")){
            int day = Integer.parseInt(line);  
            if (0 < day && day < 32){  
                return day;  
            } else {  
                System.out.println("please use a valid number");       
            }  
        } else {  
            System.out.println("please use a number");  
        }  
    }
}

public static void main(String[] args) {
    int day = getDay();
    System.out.println(day);  
}

Or you could use a break:
Scanner scan = new Scanner(System.in);
System.out.println("Insert Day");
int day = -1;
while (true){  
    line = scan.nextLine();  
    if (line.matches(".*\\d.*")){
        day = Integer.parseInt(line);  
        if (0 < day && day < 32){
            break;
        } else {  
            System.out.println("please use a valid number");       
        }  
    } else {  
        System.out.println("please use a number");  
    }  
}

Or you could use your while condition:
int day = -1;
Scanner scan = new Scanner(System.in);
System.out.println("Insert Day");
while (day < 1 || day > 31){  
    line = scan.nextLine();  
    if (line.matches(".*\\d.*")){
        day = Integer.parseInt(line);  
        if (day < 1 || day > 31){
            System.out.println("please use a valid number");       
        }  
    } else {  
        System.out.println("please use a number");  
    }
}

Also, you can simplify your code by using the NumberFormatException parseInt throws, instead of trying to validate it yourself with a regular expression:
int day = -1;
Scanner scan = new Scanner(System.in);
System.out.println("Insert Day");
while (day < 1 || day > 31){
    line = scan.nextLine(); 
    try { 
        day = Integer.parseInt(line);
        if (day < 1 || day > 31){
            System.out.println("please use a valid number");       
        }  
    } catch (NumberFormatException e) {
        System.out.println("please use a number");  
    }
}

