[Solved] RILED String with Java

RILED: Oh my God!!! Someone is trying to break into Anna University’s Database and steal sensitive research information. It is now up to us to stop this attack. Fortunately our defense mechanisms have traced the attacks to their source. The fastest way to stop the attacks is to disable the source. So all we need to do is to teach that guy a lesson, by planting a virus in his own system. But before we can do that, we need to break through all the layers of the security he has put around himself.
Our sources tell us that the first layer is based on ASCII encryption. We must penetrate through this layer as fast as we can to reach the source…

The password to his system is a single character which is the average of the ascii values of his username.

Given the user name, write a program to find the password.

Input Format

Input consists of a single string which corresponds to the username of the attacker. The length of the string should be between 2 and 50, both inclusive..

Output Format:

Output consists of a single character.

Sample Input 1

 abcd

Sample Output 1

 b

Sample Input 2

 reverse

Sample Output 2

 m

Solution

import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        int i;
        Scanner sc = new Scanner(System.in);
        String oldString;
        int asciivalueSum = 0, asciivalueAvg;

//sauravhathi
        oldString = sc.nextLine();
        for (i = 0; i < oldString.length(); i++) {
            asciivalueSum = asciivalueSum + (int) oldString.charAt(i);
        }
        asciivalueAvg = asciivalueSum / oldString.length();
        System.out.print((char) asciivalueAvg);
    }
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *