Question

In: Computer Science

In Java form Declare and assign a char variable called myLetter to z. Write a Java...

In Java form

  1. Declare and assign a char variable called myLetter to z.
  2. Write a Java statement that makes myLetter uppercase.
  3. Write a java statement that finds out if myLetter is a digit.
  4. Write a java statement that finds out if myLetter is an upper case letter.
  5. Assume myLetter = ‘Z’;
    What is the output for System.out.print(myLetter++);
  6. Assume myLetter = ‘Z’;
    What is the output for System.out.print(++myLetter);
  7. Assume myLetter = ‘Z’;
    What is the output for System.out.print(myLetter--);
  8. What happens when a floating-point data type, like double, is cast into a char? (page 127)
  9. Evaluate the following Java statement: char c = 90;
  10. What Java method in the Character class lets me know if my character is a letter?

Solutions

Expert Solution

Answers:

//  Declare and assign a char variable called myLetter to z.
         char myLetter = 'z';
         
        //  Write a Java statement that makes myLetter uppercase
         myLetter -= 32; 
        System.out.println(myLetter);
        
        // Write a java statement that finds out if myLetter is a digit
        boolean flag = Character.isDigit(myLetter);
        System.out.println(myLetter + " is Character: " + flag);
        
        // Write a java statement that finds out if myLetter is an upper case letter.
        flag =Character.isUpperCase(myLetter);
        System.out.println(myLetter + " is uppercase letter: " + flag);
        
        //Assume myLetter = ‘Z’;
        // What is the output for System.out.print(myLetter++);
        //ans: Z.
        myLetter = 'Z';
        System.out.println(myLetter++);
        // Assume myLetter = ‘Z’;
        // What is the output for System.out.print(++myLetter);
        // ans: [
        myLetter = 'Z';
        System.out.println(++myLetter);
        
        // Assume myLetter = ‘Z’;
        // What is the output for System.out.print(myLetter--);
        // ans: Z
        myLetter = 'Z';
        System.out.println(myLetter--);
        
        // What happens when a floating-point data type, like double, is cast into a char?
        //ans: it narrow down the float to its integer part
        myLetter = (char)66.37;   //equal to myLetter = 66;
        System.out.println(myLetter);
        
        // Evaluate the following Java statement: char c = 90;
        char c=90;
        // What Java method in the Character class lets me know if my character is a letter?
        System.out.println(Character.isLetter(c));

Java code: Main.java

public class Main{
        
     public static void main(String []args){
        //  Declare and assign a char variable called myLetter to z.
         char myLetter = 'z';
         
        //  Write a Java statement that makes myLetter uppercase
         myLetter -= 32; 
        System.out.println(myLetter);
        
        // Write a java statement that finds out if myLetter is a digit
        boolean flag = Character.isDigit(myLetter);
        System.out.println(myLetter + " is Character: " + flag);
        
        // Write a java statement that finds out if myLetter is an upper case letter.
        flag =Character.isUpperCase(myLetter);
        System.out.println(myLetter + " is uppercase letter: " + flag);
        
        //Assume myLetter = ‘Z’;
        // What is the output for System.out.print(myLetter++);
        //ans: Z.
        myLetter = 'Z';
        System.out.println(myLetter++);
        // Assume myLetter = ‘Z’;
        // What is the output for System.out.print(++myLetter);
        // ans: [
        myLetter = 'Z';
        System.out.println(++myLetter);
        
        // Assume myLetter = ‘Z’;
        // What is the output for System.out.print(myLetter--);
        // ans: Z
        myLetter = 'Z';
        System.out.println(myLetter--);
        
        // What happens when a floating-point data type, like double, is cast into a char?
        //ans: it narrow down the float to its integer part
        myLetter = (char)66.37;   //equal to myLetter = 66;
        System.out.println(myLetter);
        
        // Evaluate the following Java statement: char c = 90;
        char c=90;
        // What Java method in the Character class lets me know if my character is a letter?
        System.out.println(Character.isLetter(c));
     }
}

Output:


Related Solutions

A) Declare a String variable called myString0 and initialize it to "Java". B) Declare a String...
A) Declare a String variable called myString0 and initialize it to "Java". B) Declare a String variable called myString1 and initialize it to "Programming". C) Declare a String variable called myString2 and initialize it to "Language". D) Print the concatenation of myString0 + " is a " + myString1 + " " + myString2 + ".". E) Print the sum of the lengths of myString1 and myString2 (must call the length() method). F) Print the 2nd, 4th, and 7th character...
Part A: Write a set of statements that declare a variable of type double called yourNum,...
Part A: Write a set of statements that declare a variable of type double called yourNum, then prompts the user to input a value which gets stored into that variable. Part B: Write a set of statements that displays the phrase "Even Number!" when the value in the variable count is an even number but displays the phrase “That is odd” otherwise. Declare and initialize all variables. Part C: Write the necessary code to swap (exchange) the values in two...
Python HW with Jupyter Notebook Declare a variable named DATA as a dictionary object. Assign the...
Python HW with Jupyter Notebook Declare a variable named DATA as a dictionary object. Assign the set of key/value pairs shown below. Create a function named iter_dict_funky_sum() that takes one dictionary argument.    Declare a running total integer variable. Extract the key/value pairs from DATA simultaneously in a loop. Do this with just one for loop and no additional forms of looping. Assign and append the product of the value minus the key to the running total variable. Return the funky...
Write a c statement to declare variables of primitive data types, and assign values to the...
Write a c statement to declare variables of primitive data types, and assign values to the variables. Use common control structure in c, such as if, switch, break, for, while statements. Write a c program that takes command line parameters, and perform some computation based on the command line input. Write c statements to generate random number within a certain range. Write a c statement to declare array variables of primitive data types, and assign values to the elements of...
Java program Write a class called Animal that contains a static variable called count to keep...
Java program Write a class called Animal that contains a static variable called count to keep track of the number of animals created. Your class needs a getter and setter to manage this resource. Create another variable called myCount that is assigned to each animal for each animal to keep track of its own given number. Write a getter and setter to manage the static variable count so that it can be accessed as a class resource
Java: Declare a two-dim array that represents five students with four test scores. Assign 100 for...
Java: Declare a two-dim array that represents five students with four test scores. Assign 100 for all tests to all students. Change the 3rd student’s test 2 to 50. Change the last student’s last test to 87 Print out all test scores. Calculate the total points of all tests of all students
Write a Java method that takes an array of char and a String as input parameters...
Write a Java method that takes an array of char and a String as input parameters and and returns an boolean. The method returns true if we can find the input string inside the array by starting at any position of the array and reading either forwards or backwards.
Define a char variable. Read a char value from the keyboard into the variable. Print the...
Define a char variable. Read a char value from the keyboard into the variable. Print the variables value.
write a Java program Write a program to assign a letter grade according to the following...
write a Java program Write a program to assign a letter grade according to the following scheme: A: total score >= 90 B: 80 <= total score < 90 C: 70 <= total score < 80 D: 60 <= total score < 70 F: total score < 60 Output - the student's total score (float, 2 decimals) and letter grade Testing - test your program with the following input data: test1 = 95; test2 = 80; final = 90; assignments...
Write z = -6 + 6i in polar form. Write z = 9 - 3sqrt3i in...
Write z = -6 + 6i in polar form. Write z = 9 - 3sqrt3i in polar form. Write z = 2 (cos 5pi/6 + i sin 5pi/6) in rectangular form.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT