Thread: WAP to return string, from a given array of numbers, corresponding alphabet numbers in reverse order

Forum : Problem Solving   20 Nov, 2018 05:25
User Image
Satish15

Newbie

Joined: 5 Jan, 2018

Points: 105

Threads: 13

Posts: 7

WAP to return string, from a given array of numbers, corresponding alphabet numbers in reverse order

| Quote Date : 20 Nov, 2018    Views:296    

Explanation:-
Assume alphabet numbers order: [a=26,b=25,........z=1]
Given array of number is: [5,15,19,8,4]
Then I output string should be :vlhsw





Comments

User Image
remo1249

Newbie

Joined : 20 Feb, 2018

Points : 100

Threads: 2

Posts: 4

Re: WAP to return string, from a given array of numbers, corresponding alphabet numbers in reverse order

Reply Date : 21 Nov, 2018



public class ReturnStringFromNumbers {
    static int i[]= {1,15,19,8,4,2};
    public static void main(String[] args) {
        char c[] = new char[i.length];
        int j=122;//Anscii
        for (int m = 0; m < i.length; m++) {
            if(i[m]<=26) {
                int v=j-i[m];
                //System.out.println((char)v);
                c[m]=(char) v;
                if(m>=i.length-1)
                {
                    System.out.println(c);
                }
            }
            else {
                System.out.println("enter the numbers ranging from 1-26");
            }
        }
    }

User Image
ekkumar

Newbie

Joined : 5 Dec, 2018

Points : 100

Threads: 0

Posts: 2

Re: WAP to return string, from a given array of numbers, corresponding alphabet numbers in reverse order

Reply Date : 5 Dec, 2018



import java.util.*;
class ac{
    //main method
    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        System.out.print("Enter how manyelements want to: ");
        int num=scn.nextInt();
        int temp;
        int []a=new int[num];
        for(int i =0;i<a.length;i++){
            System.out.print("Enter the "+(i+1)+"index is :");
            temp=scn.nextInt();
            if(temp >=1 && temp<= 26)
                a[i]=temp;
            else{
                System.out.println("Enter the value between 1 to 26");
                System.exit(0);
            }
        }
        int []b=new int[a.length];
        for(int i =0;i<a.length;i++){
            b[i]=123-a[i];
            System.out.print((char)b[i]);
        }
    }
}

Load More

No More Comments