What Will Be Output For The Given Code Taking Input String As #2211
What will be output for the given code taking input string as “nvaeducation”?</p> <pre><code class="language-c"> package com.nvaeducation.setandstring; import java.util.Scanner; public class MonoalphabeticCipher { public static char p[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; public static char ch[] = { 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M' }; public static String doEncryption(String s) { char c[] = new char[(s.length())]; for (int i = 0; i < s.length(); i++) { for (int j = 0; j < 26; j++) { if (p[j] == s.charAt(i)) { c[i] = ch[j]; break; } } } return (new String(c)); } public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the message: "); String en = doEncryption(sc.next().toLowerCase()); System.out.println("Encrypted message: " + en); sc.close(); } }</code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs122 Data Communication and Computer Network. It can also be found in gs gs122 Cryptography - Monoalphabetic Cipher - Quiz No.1.
What will be output for the given code taking input string as “nvaeducation”?
package com.nvaeducation.setandstring; import java.util.Scanner; public class MonoalphabeticCipher { public static char p[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; public static char ch[] = { 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M' }; public static String doEncryption(String s) { char c[] = new char[(s.length())]; for (int i = 0; i < s.length(); i++) { for (int j = 0; j < 26; j++) { if (p[j] == s.charAt(i)) { c[i] = ch[j]; break; } } } return (new String(c)); } public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the message: "); String en = doEncryption(sc.next().toLowerCase()); System.out.println("Encrypted message: " + en); sc.close(); } }
Encrypted message: LQFYGXFRKN
Encrypted message: NKRFXGYFQL
Encrypted message: lqfygxfrkn
Encrypted message: nkrfxgyfql
Similar question(s) are as followings:
Online Quizzes of gs122 Data Communication and Computer Network
Sorting - Insertion Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.3
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - LSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes