Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

What are the strengths and weaknesses of e-distribution?

Answered: 1 week ago

Question

Patient sits in waiting area (11 minutes).

Answered: 1 week ago