Find solutions to your problems with the expert advice available on IDNLearn.com. Find in-depth and accurate answers to all your questions from our knowledgeable and dedicated community members.

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);

We appreciate your presence here. Keep sharing knowledge and helping others find the answers they need. This community is the perfect place to learn together. IDNLearn.com is dedicated to providing accurate answers. Thank you for visiting, and see you next time for more solutions.