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
You have stumbled on an unknown civilization while sailing around the world. The people, who call themselves Zebronians, do math
marshall27 [118]

Answer:

a. 6 bits

b. 1

Explanation:

Ans (a)

40 Characters need to be represent by binary coded Zebronian (BCZ) , So You will need 6 bits.

5 bits wold only give you 32 = 2 x 2 x 2 x 2 x 2 unique characters.

So 6 bits would allow you to represent 64 characters.

Ans(b)

BCD = Binrary Coded Decimal is very common in electronics, particularly it displays numerical data.

BCD Encodes each digit of a decimal number into 4 digit binary form.

Each decimal digit is indiviidually converted to oits binary equivalent

For Example : 146 , the decimal degits are replaced by 0001 , 0100 and 0110 respectively

Addition

1 0 = 10 is binary value of 2 2

+1 1 = 11 is binary value of 3 + 3

---------- -----------

1 0 1 5 Ans

Subtraction

1 1= binary value of 3 3

- 1 0 = binary value of 2 - 2

--------- -----------

0 1 1 Ans

6 0
3 years ago
A blank is the full web Address for particular website<br> (Computer technology)
Yuki888 [10]
What do you mean by that
6 0
3 years ago
a flow chart is the _______ representation of the sequence of steps required of steps required to solve a particular problem​. I
Eddi Din [679]

Answer:

A flowchart is simply a graphical representation of steps. It shows steps in sequential order and is widely used in presenting the flow of algorithms, workflow or processes. Typically, a flowchart shows the steps as boxes of various kinds, and their order by connecting them with arrows.

7 0
3 years ago
Does anybody play nitro type
vlabodo [156]

Answer: Nah

Explanation: it kinda sucks and is a waste of time, play better games lol

3 0
3 years ago
Read 2 more answers
Does giving a set instructions to someone, or a recipe for a cake represent an algorithm?
prohojiy [21]
I dont know sorry if i wasted this answer
4 0
3 years ago
Other questions:
  • A user reports his or her computer is slow to boot. You check the boot order and determine that the computer is checking the C d
    12·1 answer
  • If some1 emails u and u want to know who it was how do u find that out
    10·2 answers
  • 3. What are the first steps that you should take if you are unable to get onto the Internet? (1 point)
    15·1 answer
  • Is the answer a,b,c,d
    8·1 answer
  • What is the difference between a rack and a tower?
    8·1 answer
  • E-mail messages, instant messages (IMs), or text messages sent and/or received within an organization a. are not included on a r
    9·1 answer
  • Your it department enforces the use of 128-bit encryption on all company transmissions. your department also protects the compan
    13·1 answer
  • How does abstraction help us write programs
    11·1 answer
  • The most common types of effects include entrances and exits
    11·1 answer
  • JAVA CODE.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!