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
I try to make an account so I can have some help, but it always says "We’re sorry, but we are not able to complete your registra
Romashka-Z-Leto [24]

Answer:

that keeps happening to me too i sent them a email and they said they are trying to fix it

8 0
3 years ago
You've formatted the first paragraph of a document. What button can you use to apply the formatting from the first paragraph to
ch4aika [34]
C. Copy which you can access by Ctrl C then paste with Ctrl V
3 0
4 years ago
Read 2 more answers
In cells D6 through D8, enter formulas to calculate the values of the stocks. The formulas should multiply the number of shares
irakobra [83]

Answer:

Answer is attached. If you have any further questions, feel free to ask. I also completed the total investment value.

Download xlsx
6 0
3 years ago
How much water does the Hill family use per week?
Thepotemich [5.8K]

Answer:

The Hill family uses69 pints

Explanation:

bc why not

4 0
3 years ago
A ________ is a type of page break. section break column column break section
Setler [38]
Bar of soap will break
7 0
4 years ago
Other questions:
  • A process-based DO/S must synchronize actions across the network. When a process reaches a point at which it needs service from
    6·1 answer
  • Store shelves are empty during periods of Excess Demand. What is another term for Excess Demand?
    8·1 answer
  • ________ network each device is connected directly to a central network switch.
    8·1 answer
  • What is the meaning of Android
    12·2 answers
  • The Role of Computer
    15·1 answer
  • Justin bought some yarn from his favorite craft store. He can make 1 scarf with 3/5 of a ball of yarn. If he purchases 15 balls
    14·1 answer
  • What is difference between augmented reality and mixed reality?​
    11·1 answer
  • Which componet is the smallest unit in a spreadsheet
    15·1 answer
  • Trish has bought a new computer that she plans to start on after a week
    5·1 answer
  • Write a program to
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!