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
How could social media have a negative impact if not used properly when seeking employment
castortr0y [4]
Before hiring someone, employers often check the social media pages of people applying for a job. If their social media account has content not up to the company's standards, they may not get the job. 
8 0
3 years ago
________is one of the most popular payment gateways founded in in December 1998​
iren2701 [21]

paypel is the most popular

6 0
2 years ago
Lenny is working as an apprentice to a typesetter. He has been told to sort different font stamps based on their type. Match the
DedPeter [7]

Answer:

Serif without kerning is the first one

Italic is the second one

Bold is the third one

Serif with kerning is the fourth one

Explanation:

I had this question and got this correct

3 0
1 year ago
The collection of computer instructions and other files that constitute a piece of software is
lutik1710 [3]
The answer would be
A. Codebase

8 0
2 years ago
Read 2 more answers
A linear gradient can be positioned from left to right, top to bottom, or on any angle?
Harman [31]

from left to right because it is used more in expressions

3 0
2 years ago
Other questions:
  • You start up your laptop while getting a coffee across the room. You hear the usual chimes and doinks as it starts up. When you
    14·2 answers
  • An online service allows users to integrate their phonebook with their social media profiles and stores it on the cloud. The pho
    12·1 answer
  • What are the advantages of Napier bones?​
    15·1 answer
  • Write a MATLAB program to accomplish the following: Create two vectors, a and b, where vector a contains all positive integers l
    10·1 answer
  • if a second system failure occurs while the first recovery is in progress, what needs tobe done after the system recovers for th
    11·1 answer
  • A ___________ variable is used to add up a set of values. fill in the blank
    8·1 answer
  • List of rules for expert systems​
    6·1 answer
  • List 5 differences between monitors and printers​
    14·1 answer
  • What is the bandwidth for asymmetric digital subscriber line<br> (ADSL)?
    10·2 answers
  • Visual Basic: What are arrays, please give an example code.
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!