Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java class with the following two user-defined methods: Write a value-re

ID: 3940431 • Letter: W

Question

Write a java class with the following two user-defined methods:

Write a value-returning method named isVowel, that returns the boolean value true if a given character is a vowel, and otherwise returns the boolean value false.

Write a value-returning method named reverseDigit, that takes an int (integer) as a parameter and returns the number with its digits reversed as an int. For example, calling reverseDigit(12345) returns the int value of 54321.

Write the main method for this class to test the above two user-defined methods.

Explanation / Answer

Hi, Please find my implmenetation.

Please let me know in case of any issue.

import java.util.Scanner;

public class JavaProgram {

  

   //1. isVowel

   public static boolean isVowel(char c){

      

       // if it is not letter

       if(! Character.isLetter(c))

           return false;

      

       // getting lower case representation of c

       char lower = Character.toLowerCase(c);

      

       if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')

           return true;

       else

           return false;

   }

  

   public static int reverseDigit(int n){

      

       int reverse = 0;

      

       while(n > 0){

          

           reverse = reverse*10 + n%10;

           n = n/10;

       }

      

       return reverse;

   }

  

   public static void main(String[] args) {

      

       Scanner sc = new Scanner(System.in);

       System.out.print("Enter a character: ");

       char c = sc.next().charAt(0);

      

       System.out.println(c+ " is vowel: "+isVowel(c));

      

       System.out.print("Enter a number: ");

       int n = sc.nextInt();

       System.out.println("Reverse of "+n+" : "+reverseDigit(n));

      

   }

}

/*

Sample run:

Enter a character: g

g is vowel: false

Enter a number: 6543

Reverse of 6543 : 3456

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote