Java: name and age entry with range verification via /r/learnprogramming


Java: name and age entry with range verification

Again I'm a little stuck. So I have to create a program that will tally sudoku games for a player but first they need to enter their name and age. I'm having problems with the age part.

I have it as an int and I want to make sure the entry falls in a range between 10 and 90, if outside of that range it just ask for the user to enter it again. At the moment with the pasted code I get "illegal start of expression" in netbean.

import java.util.*; public class TP2 { public static void main(String[] args) { Scanner entry = new Scanner (System.in); String name; int age; System.out.println("Welcome to SUDOKU Statistic calculator"); System.out.println("Enter your name (First Last)"); name = entry.nextLine(); while (!name.matches("[a-zA-Z , -]+")){ System.out.println("Error, please enter a valid name (Lettre (minuscule et majuscule), espace et -"); name = entry.nextLine();} System.out.println("Enter your age (10-90)"); age = entry.nextInt(); while (age < 10 && > 90) { System.out.println("Error, please enter a valid age between 10 and 90"); age = entry.nextInt();} System.out.println("\nYour name is: "+ name +""); System.out.println("\nYour age is: "+ age +""); } } 

Submitted July 12, 2017 at 12:03AM by Bender248
via reddit http://ift.tt/2u76Nik

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s