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
A computer interacts with their environment by...
statuscvo [17]

Answer:

interacting with people

yes

Explanation:

7 0
3 years ago
According to Darwin’s theory of evolution, differences between species may be a result of which of the following?
ArbitrLikvidat [17]

Explanation:

Your answer is C natural selection.

8 0
3 years ago
Read 2 more answers
An inner drive to work hard and well is:
Nikolay [14]

A word ethic would be the answer

3 0
3 years ago
what happened to the velocity at 30 centimeters down the ramp compared to 10 centimeters down the ramp ?
posledela

Answer:

The velocity at 30 centimeters down the ramp will be considerable higher compared to 10 centimeters down the ramp.

Explanation:

It is a non lineair problem, since the speed is increasing while rolling down the ramp.

We will expect therefore, that the graph of speed (on the y-axis) and position (on the x-axis) will NOT be a streight line.

if you could plot some values given, with speed (on the y-axis) and position (on the x-axis), then you could draw a smooth line through them, which would give an estimate of all points in between them.

What can be stated with only so limited information, is that the velocity at 30 centimeters down the ramp will be considerable higher compared to 10 centimeters down the ramp.

6 0
3 years ago
A security system is desired that can be used to detect whenever any one of two doors in a house and any one of two windows are
Sedaia [141]

Answer:

Z = A + B

Explanation:

The logic network can be seen attached below. This basically shows that if either of the two inputs are True then the output would apply. In this scenario, the output would be the alarm going off. Since either one of the windows being opened in this scenario would set off the alarm then the logic operator that needs to be used would be OR. In this scenario, the two windows are represented by the variables A and B while the output can be represented by the variable Z. Using these variables, we can apply the following boolean expression.

Z = A + B

8 0
3 years ago
Other questions:
  • How do Hlookup and Vlookup differ?
    5·2 answers
  • Help with this chart please
    9·1 answer
  • A variation of pronounce is a. Proclaim c. Produce b. Profound d. Pronunciation Please select the best answer from the choices p
    11·1 answer
  • What is the importance of computer application to statistics​
    6·1 answer
  • What is Microsoft Word an application used for word-processing, an example of?
    10·1 answer
  • What is targets net worth in 2020 (i will see if you put in 2019)
    11·1 answer
  • What is the purpose of "display:table"?
    10·1 answer
  • HELP PLEASEEEE!!!!!!!
    5·1 answer
  • Write a program that lets the user perform arithmetic operations on fractions. Fractions are of the form a/b, in which a and b a
    11·1 answer
  • A template slide that controls the formatting of all other slides in the presentation is called a _________.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!