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]
2 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]2 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
Which option is used in emails to inform the recipient that they should exercise discretion in accordance with sharing the conte
Kay [80]
Priority levels hehe good luck!
5 0
3 years ago
Sarah has prepared a project document about the small and medium-sized companies in the United States. While proofreading, she r
erik [133]
The answer is F7. When you click F7 it highlights key words.<span />
3 0
3 years ago
Read 2 more answers
Images, symbols, and diagrams are types of
kifflom [539]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The correct answer to this question is :

Graphics

Because Graphics are the visual representation of information without text. Images, symbols, and diagrams are types of graphics. These graphics can be used in presentations to present information visually.

While other options are not correct because:

Art objects are some images or painting that is the artistic creation of aesthetic value. While graphs are the visual presentation of data and there are different presentation objects in PowerPoint such as images, symbols, text, and diagrams, etc. But it is noted that images, symbols, and diagram are not types of presentation objects but it is a type of graphics elements/objects.

4 0
3 years ago
Why is audio greyed out on powerpoint ms office 2011?
-BARSIC- [3]
Because its a old type of software and probably wont run on your computer
7 0
3 years ago
What amount of memory enough to store alatter of the alphabet or store a small number​
laiz [17]

Answer:

It can be "ON" or "OFF". So it can store the numbers 1 and 0, but it certainly doesn't have the capacity to store a letter of the alphabet.

Explanation:

3 0
2 years ago
Other questions:
  • How designers have created products from waste materials?
    7·1 answer
  • The primary function of application software is to apply the power of the computer to enable people, workgroups, and the entire
    7·1 answer
  • Who knows a website that can connect videos in your phone
    8·1 answer
  • On his website, Mario has a video that visitors must click to play. He wants the video to play automatically when the page loads
    9·1 answer
  • Consider the following code:
    12·1 answer
  • Which elements of text can be changed using automatic formatting? Check all that apply.
    8·1 answer
  • 1. Which sentence best expresses the main idea
    12·1 answer
  • Is anyone else having issues with brainly not working? Everytime I click on a answer it only comes up with the 7 month trail thi
    12·1 answer
  • Which of the following statements best compares and contrasts hot and cold type?
    12·1 answer
  • Help me please, I'm attempting a test<br>​
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!