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

Forum : Problem Solving   25 Days ago
User Image
Satish15

Newbie

Joined: Jan 5, 2018

Points: 105

Threads: 10

Posts: 5

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

| Quote Date : Nov 20, 2018    Views:166    

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
ekkumar

Newbie

Joined : Dec 5, 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 : Dec 5, 2018

import java.util.*;
class ac{

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

User Image
remo1249

Newbie

Joined : Feb 20, 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 : Nov 21, 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");
}
}
}

Load More

No More Comments