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
Using the flowchart below, what value when entered for Y will generate a mathematical error and prevent our flowchart from being
nexus9112 [7]

Answer:

The answer is the last choice that is "None of these values will produce a mathematical error".

Explanation:

In this question, the above given choice correct because neither of the flowchart procedures could trigger a mathematical error. This error could not be induced by multiplication, addition and subtraction, and the only division by 15. It is the only divide by 0, that's why the above flowchart will produce a mathematical error.

4 0
3 years ago
Which extension is appropriate for Word document templates?
Ronch [10]

Answer:

<em><u>DOCX pretty sure</u></em>

<em><u /></em>

<em><u>hope that this helps :)</u></em>

<em></em>

5 0
3 years ago
Read 2 more answers
what is the restaurant with the black pom tree and yellow backround three letter name from hi guess the restaurant
vekshin1
In 'N' Out, and KFC (Kentucky Fried Chicken)
7 0
3 years ago
Read 2 more answers
Write an<br>algorithm and draw flow chart to<br>find greatest among 2 numbers​
antoniya [11.8K]

Answer:the question is not right

Explanation:

8 0
2 years ago
Optimizing a PC’s performance often involves utilities that can defragment disks, clean a system’s Registry, scan for malware, r
KATRIN_1 [288]

Answer:

a. True

Explanation:

PC's sometimes runs slowly and on the long run cost money. Optimizing performance involves running software utilities that could restore speed and efficiency.

Scanning for malware/ virus , cleaning system registry, uninstalling unused program,  deleting unnecessary files, disk defragment , updating of windows software and setting up the browser are ways to optimize your pc's performance.

3 0
3 years ago
Other questions:
  • type the correct answer in the Box spell the words correctly Caleb is working on a simple logic base program to stimulate the ga
    5·2 answers
  • Let's assume that the smallest possible message is 64 bytes (including the 33-byte overhead). if we use 100base-t, how long (in
    10·1 answer
  • When ordering a new​ zagflatz, customers must choose the style of three major​ components, each of which has about ten variation
    6·1 answer
  • Explain the role of the domain name system
    15·1 answer
  • When activated, an Excel object has all the features of an Excel
    8·2 answers
  • As a safe driver, you cannot, __________
    13·1 answer
  • ______allow you to select elements that are in a certain state, such as when the mouse if hovering over an element
    14·1 answer
  • A human interest story is an example of hard news.<br> O True<br> O False HEL
    15·1 answer
  • Define the term visual as used in visual programming
    9·1 answer
  • We can find out how robots work by looking in detail at the smaller parts. What do we call this?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!