Question: Beginner Java Program- boolean, do/while loops, for loops, if and if/else loops-Please help!!! Write a program that checks the properness of a given variable name.

Beginner Java Program- boolean, do/while loops, for loops, if and if/else loops-Please help!!!

Write a program that checks the properness of a given variable name. More specifically, your program should specify whether a user-entered variable name is:

(1) illegal,

(2) legal, but uses poor style, or

(3) good.

There are different opinions as to what constitutes good style for a variable name. For this program, check for good style using these rules:

(1)Only use letters and digits.

(2)Use a lowercase letter for the first character.

You dont need to check for an uppercase letter for the first letter in the second word, third word, etc.

My Program So Far :

import java.util.Scanner;

public class Lab08

{

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

String variableName;

System.out.println("Enter a variable name:");

variableName=input.next();

for(int count = 0; count < variableName.length(); count++)

{

if(!(Character.isLetterOrDigit(variableName.charAt(count))))

{

System.out.print("Illegal.");

}

else if(Character.isUpperCase(variableName.charAt(0)))

{

System.out.println("Legal, but uses poor style.");

}

else if(Character.isDigit(variableName.charAt(0)))

{

System.out.println("Legal, but uses poor style.");

}

else if(Character.isLowerCase(variableName.charAt(0)))

{

System.out.println("Good.");

}

}

input.close();// closes the scanner

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!