1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
erastova [34]
3 years ago
10

Just a quick question, how do you set something == to char and int in an if statement (java)

Computers and Technology
1 answer:
Troyanec [42]3 years ago
3 0

This is the requested code in java.

public class <em>CharTest</em> {

   public static String checkCharacter(String text, int index) {

       if (0 <= index && index <= text.length()) {

           char ch = text.charAt(index);

           if (Character.isLetter(ch)) {

               return ch + " is a letter";

           } else if (Character.isDigit(ch)) {

               return ch + " is a digit";

           } else if (Character.isWhitespace(ch)) {

               return ch + " is a whitespace character";

           } else {

               return ch + " is an unknown type of character";

           }

       } else {

           return "index " + index.toString() + " is out of range";

       } // <em>end if</em>

   } // <em>end function checkChar()</em>

   public static void <em>main</em>(String[] args) {

       // <em>Test the three samples from the specification.</em>

       System.out.println(<em>checkCharacter</em>("happy birthday", 2));

       System.out.println(<em>checkCharacter</em>("happy birthday", 5));

       System.out.println(<em>checkCharacter</em>("happy birthday 2 you", 15));

   } // <em>end function main()</em>

} // <em>end class CharTest</em>

The function <em>checkcharacter</em>(text, index) returns a string value describing the kind of character found at the position in text specified by index; whether it was a letter, digit, whitespace, or an unknown kind of character.

How it does that is to make use of respective functions defined within the Character class in java. That is

  • isLetter(char) returns a bool specifying if the char parameter is a letter.
  • isDigit(char) returns a bool specifying if the char parameter is a digit.
  • isWhitespace(char) returns a bool specifying if the char parameter is a whitespace character.

It calls these functions in an if statement. These else part of the if statement is then executed if the character is neither a <em>letter</em>, <em>digit</em>, or <em>whitespace</em>.

Finally, the function main() calls <em>checkCharacter</em>() three times to test the function and return the results to the console.

Another example of a java program on characters is found in the link below

brainly.com/question/15061607

You might be interested in
What software is typically used for larger systems?
Degger [83]
Microsoft Server, (often clippy is used as well)
4 0
3 years ago
What is the binary for O?​
nevsk [136]

Answer:

01001111

Explanation:

8 0
3 years ago
Read 2 more answers
1. How fast do human beings walk?
zepelin [54]

Answer:

a.about 3 or 4 miles per hour

8 0
3 years ago
Read 2 more answers
Main components of Adobe photoshop are. ...............
Sergio039 [100]

Answer:

The correct option is;

d) All of this

Explanation:

The main components of Adobe Photoshop are;

1) Title bar displays the name of the application, as well as the name of the current document and it is located at the top of the document window

2) Tool bar is the component of the interface design in which on-screen buttons, menus, icons, and other features for input and output are placed

The tools palette is the toolbar in Adobe Photoshop

3) Menu bar consists access to the basic components such as file, edit, image, layer, used to create new jobs, compose, and edit images.

5 0
3 years ago
Dropbox is an example of ________. Bluetooth technology optical storage SSD technology cloud storage
inessss [21]

IaaS

Laas is Framework as a help are online administrations that give significant level APIs used to dereference different low-level subtleties of basic organization foundation like actual registering assets, area, information dividing, scaling, security, reinforcement and so forth

7 0
3 years ago
Other questions:
  • Which of these printers would be the most suitable for printing a large number of high quality black and white printouts?
    15·1 answer
  • Which mode of IPSec should you use to assure the integrity and confidentiality of data within the same LAN?a. AH promiscuous mod
    6·1 answer
  • Can some one fix this <br> input ("Enter a number: ") <br> print (num * 8)
    9·1 answer
  • Teachers in most school districts are paid on a schedule that provides a salary based on their number of years of teaching exper
    7·1 answer
  • URLs are directions that browsers follow in order to find specific web page files. What is the first part of the URL that is the
    14·1 answer
  • What term is given to pieces of computer software that allow you to manage your e-mail from your computer?
    12·1 answer
  • Which of the following skills do employers in any field expect their employees<br> to have?
    5·1 answer
  • Which object event is an indication that something has been created but not committed into the database?
    13·1 answer
  • Complete the sentence.<br> In your program, you can open
    5·1 answer
  • Television, the internet, and smartphones are different communication _______blank hsn uses in its imc.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!