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
Which of the following will increase the level of security for personal and confidential information on a mobile device if the d
Soloha48 [4]
I believe is a and c.
8 0
4 years ago
Choose the word pair that would best complete this analogy <br> annihilation : obliteration
iogann1982 [59]
Annihilation : obliteration

if the choices were:

strategy : tactics
sensation : numbness
deliberation : impulsiveness
endeavor : quit 

Then the word pair that would best complete the analogy is:
STRATEGY : TACTICS

Annihilation and obliteration are synonymous. In fact, annihilation is defined as complete destruction or complete obliteration. Obliteration is defined as total destruction.

Strategy and tactics are also synonymous. They both mean a system or mode of procedure or a plan of action.

The rest of the choices are antonyms.
8 0
3 years ago
Pls help.
melisa1 [442]

Answer:

First one would be work ethic.

Second one would be communication.

Third one would be adaptability.

Fourth one would be creativity.

(These are all guesses tho, so i'm not 100% sure !!)

Explanation:

6 0
3 years ago
Read 2 more answers
As designs incorporate new technologies, it can seem like an actor is walking through a projection or even become part of a proj
katovenus [111]

Answer:

The answer to the given question is "True".

Explanation:

In computer science, Design is an oriented programming language, that includes text, graphics, style elements, etc.  It is used to convert the projection into 3D to 2D which means a three-dimensional to two-dimensional object and uses to display the improve projection.

That's why the answer to this question is "True".    

4 0
3 years ago
The * key on the number keypad is used for _____.
12345 [234]

Answer:

multiply

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • Write a copy assignment operator for CarCounter that assigns objToCopy.carCount to the new objects's carCount, then returns *thi
    7·1 answer
  • Is a program that allows you to view images and animations, listen to audio, and watch video files on your computer or mobile de
    11·1 answer
  • What does NVRAM stand for
    8·2 answers
  • A forensic investigation discovered that accounts belonging to employees who were terminated numerous years ago were recently us
    9·1 answer
  • Do you like Houseparty?
    7·1 answer
  • Differentiate between the broadcasting and telecommunication
    5·1 answer
  • Carbon copy others who are..
    14·2 answers
  • Consider an unpipelined or single-stage processor design like the one discussed in slide 6 of lecture 17. At the start of a cycl
    10·1 answer
  • John works for Internal Computer Specialists, a company that focuses on helping small business owners resolve MIS infrastructure
    12·1 answer
  • Peter has recently bought a media player and a digital camera. He wants to buy a memory card for these devices. Which memory dev
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!