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
Which of the following terms best describes the product development life cycle process?
RUDIKE [14]

Answer:

D

Explanation:

Evaluative

3 0
3 years ago
Read 2 more answers
JAVA
Katarina [22]

import java.util.Scanner;

public class JavaApplication83 {

   

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Enter Strings: ");

       String word1 = scan.nextLine();

       String word2 = scan.nextLine();

       String newWord = "";

       if (word1.length() == word2.length()){

           for (int i = 0; i < word1.length(); i++)

           {

               newWord += word1.charAt(i) +""+word2.charAt(i);

           }

       

       }

       else{

           newWord = "error";

       }

       System.out.println(newWord);

   }

   

}

I hope this helps!

4 0
2 years ago
What is one invention that has had an impact on the way you live?<br><br>Write an essay
xz_007 [3.2K]
My phone duhhh. If I hadn’t had a phone I wouldn’t be able to send streaks...
8 0
3 years ago
Read 2 more answers
Write a basic program that performs simple file and mathematical operations.
Ostrovityanka [42]

Answer:

Explanation:

I have written the Python program based on your requirements.

Just give the path of the input file and the path for the output file correctly where you want to place the output file.

In, my code - I have given my computer's path to the input and output file.

You just change the path correctly

My code works perfectly and I have tested the code with your inputs.

It gives the exact output that you need.

I have attached the Output that I got by running the below program.

Code:

month_list={ "january":"1","february":"2", "march":"3","april":"4", "may":"5", "june":"6","july":"7", "august":"8", "september":"9","october":"10", "november":"11", "december":"12"} input_file=open('C:\\Users\\Desktop\\inputDates.txt', 'r') output_file=open('C:\\Users\\Desktop\\parsedDates.txt','w') for each in input_file: if each!="-1": lis=each.split() if len (lis) >=3: month=lis [0] day=lis[1] year=lis [2] if month.lower() in month_list: comma=day[-1] if comma==',': day=day[:len (day)-1] month_number=month_list[month.lower()] ans-month_number+"/"+day+"/"+year output_file.write (ans) output_file.write("\n") output_file.close() input_file.close()

- O X parsedDates - Notepad File Edit Format View Help 3/1/1990 12/13/2003

- X inputDates - Notepad File Edit Format View Help March 1, 1990 April 2 1995 7/15/20 December 13, 2003 -1

cheers i hope this helped !!

7 0
3 years ago
A private network that is accessible only to employees of the company that created it is called:
Trava [24]
Intranet is the answer to this question.

Google definition: An intranet is a network based on TCP/IP protocols (an internet) belonging to an organization, usually a corporation, accessible only by the organization's members, employees, or others with authorization.
6 0
3 years ago
Other questions:
  • You just read an msds for acetic acid. based on what you read, what type of information is included in an msds sheet? record you
    7·1 answer
  • On a spreadsheet, this is the term for a grouping of cells that touch each other and form a rectangle. An example of it would be
    13·1 answer
  • Use the Internet and other sources to research the two disadvantages of standard biometrics: cost and error rates. Select one st
    10·1 answer
  • jason works for a restaurant that serves only organic local produced what trend is this business following?
    6·2 answers
  • What do developers do to support software products?
    5·2 answers
  • A healthcare organization received notification that a hospital employee’s laptop that contained PHI was inadvertently left at a
    14·1 answer
  • A domain name is used to: *
    15·1 answer
  • Write a HTML program as shown in the output.​
    9·1 answer
  • YASHARI earns $27,000 per year, is single, and lives in Wyoming. She has $7000 in Direct Subsidized loans and another $19,000 in
    9·1 answer
  • 8) how many nanoseconds does it take for a computer to perform one calculation if it performs 6.7 x 107 calculations per second?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!