Westonci.ca is your go-to source for answers, with a community ready to provide accurate and timely information. Get quick and reliable solutions to your questions from a community of experienced professionals on our platform. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.

Write a program in Java to input a letter. If it is an uppercase letter then

encode it by next 5th letter, otherwise encode it with 3rd previous letter in the

ASCII table.​


Sagot :

Answer:

The program is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 char chr;

 System.out.print("Input Character: ");

 chr = input.next().charAt(0);

 if(Character.isUpperCase(chr) == true){      chr+=5;  }

 else{      chr-=3;  }

 System.out.println("Encode Character: "+chr);

}

}

Explanation:

This declares the character

 char chr;

This prompts for input

 System.out.print("Input Character: ");

This gets the input from the user

 chr = input.next().charAt(0);

This checks for uppercase; if true, it is encoded by the next 5th

 if(Character.isUpperCase(chr) == true){      chr+=5;  }

If lowercase, it is encoded by the previous 3rd

 else{      chr-=3;  }

This prints the encoded character

 System.out.println("Encode Character: "+chr);

Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. We hope our answers were useful. Return anytime for more information and answers to any other questions you have. We're here to help at Westonci.ca. Keep visiting for the best answers to your questions.