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

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 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 a java program to Translate or Encrypt the given string : (input char is all...
write a java program to Translate or Encrypt the given string : (input char is all in capital letters) { 15 } *) Each character replaced by new character based on its position value in english alphabet. As A is position is 1, and Z is position 26. *) New characters will be formed after skipping the N (position value MOD 10) char forward. A->A+1= B , B->B+2=D ,C->C+3=F, .... Y->Y+(25%10)->Y+5=D A B C D E F G H I...
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.
Write a java code segment to declare an array of size 10 of type String and...
Write a java code segment to declare an array of size 10 of type String and read data for them from a file, prompt user for the file name. Data is stored in a file with 1 string per line.
Write a program in c# that declare a variable and store user name jjohn in. Then,...
Write a program in c# that declare a variable and store user name jjohn in. Then, write a statement that will make your program display at the screen the content of that variable, followed by " I would like to know your height in centimeter. Please enter it:". Then, write a statement that will store the value entered by the user, allowing decimal numbers ie some precision, a fraction part. Finally, write statements (more than one can be needed) so...
Find the value of the standard normal random variable z , called z 0 such that:...
Find the value of the standard normal random variable z , called z 0 such that: a)  ?(?≤?0)=0.8998 ?0= (b)  ?(−?0≤?≤?0)=0.676 ?0= (c)  ?(−?0≤?≤?0)=0.198 ?0= (d)  ?(?≥?0)=0.1895 ?0= (e)  ?(−?0≤?≤0)=0.4425 ?0= (f)  ?(−1.11≤?≤?0)=0.8515 ?0=
In a Package called characterArray, ********JAVA CODE********** 1) Create a char array containing your full name...
In a Package called characterArray, ********JAVA CODE********** 1) Create a char array containing your full name and print it out. 2) Create an uninitialized char array and copy into it      the char array containing your full name and print it out. 3) Create a Character array and copy into it the char array containing      your full name and print it out. 4) Into the Character array, use toUpperCase() to copy the char array containing     your full name...
Write a java method that creates a two dimensional char array after asking the user to...
Write a java method that creates a two dimensional char array after asking the user to input a String text (for example, "Sara" which is entered by the user)  and String key consisting of integers (for example, 2314) only, such that int rows=(int)Math.ceil(text.length()/key.length())+1; int columns= key.length(); The method fills the 2d array with letters a String entered by the use (column by column). The method then shifts the columns of the array based on key. For example, if the user enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT