Answer to Question #306232 in Java | JSP | JSF for Vee

Question #306232

As a build up from the previous question, consider 3 possible scenario

of input : A character, number or word. You program should the do the following: In case

the input is a character it should indicate if it’s a vowel or not, when a number is entered

then it’s should check if it’s a prime and finally if a word is entered the system should check

if it’s a palindrome or not


1
Expert's answer
2022-03-05T06:48:11-0500

import java.math.*;

import java.io.*; 

import java.util.*;

import java.lang.StringBuilder;


public class MyClass {

  public static void main(String args[]) {

     

    if(args[0].matches("[aeiouy]")){

     

      System.out.println("it’s a vowel");

     

    }else if(args[0].matches("\\d+")){

       

        int number = Integer.parseInt(args[0]);

        BigInteger bigInteger = BigInteger.valueOf(number);

        boolean probablePrime = bigInteger.isProbablePrime((int) Math.log(number));

         

        if(probablePrime){

          System.out.println("it’s a prime");

        }else{

          System.out.println("it’s not a prime");

        }

    }else if(args[0].length() > 1){

       

      int boolPalindrome = args[0].compareToIgnoreCase(new StringBuilder(args[0]).reverse().toString());

       

      if(boolPalindrome == 0){

        System.out.println("It's a palindrome");

      }else{

        System.out.println("It's not a palindrome");

      }

       

    }else{

      System.out.println("it’s not a vowel");

    }

      

  }

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS