ASCII STRING FORMING







Input is taken from the user and that string is formed from scratch.
Individual character of the string is taken. Each char is incremented on its ASCII value and checked against the given string.
This process is carried out till we get all the characters of the formed string match the given string.


SourceCode:

import java.awt.Toolkit;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author sooryagangarajk
 */
public class StringMagic {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in).useDelimiter("");
        String s = in.nextLine();
        int[] cia = new int[s.length()];
        int[] ans = new int[s.length()];
        int[] ciaf = new int[s.length()];
        for (int i = 0; i < s.length(); i++) {
            cia[i] = (int) s.charAt(i);
            ciaf[i] = 0;
            ans[i] = 32;
        }
        System.out.println("------------------------------------");
        System.out.println("String forming:");
        for (int j = 0; j < 255; j++) {
            int flag = 0, count = 0;
            for (int i = 0; i < s.length(); i++) {
                if (ciaf[i] == 0) {
                    if (ans[i] != cia[i]) {
                        ans[i]++;
                        Toolkit.getDefaultToolkit().beep();
                    } else {
                        ciaf[i] = 1;
                    }

                }
                System.out.print((char) ans[i]);
            }
            try {
                Thread.sleep(500);
                for (int clear = 0; clear < 1000; clear++) {
                    System.out.println("\b");
                }
            } catch (InterruptedException ex) {
                Logger.getLogger(StringMagic.class.getName()).log(Level.SEVERE, null, ex);
            }
            for (int i = 0; i < s.length(); i++) {
                if (ciaf[i] == 1) {
                    count++;
                }
                if (count == s.length()) {
                    flag = 1;
                    break;
                }

            }
            if (flag == 1) {
                break;
            }

        }
        System.out.print(s + " "); //// S G K ////

    }
}

Comments

Popular posts from this blog

How To Configure Mail Client From "mobileconfig" File ( iOS )

How To Unsubscribe Channels All From Youtube (Using Console)

How To Deploy React Js App - Heroku