'java program to print array element when index is entered by user
Forgive me if my question is stupid, I am a beginner, I found some Java code in which html components and some data were encoded and stored in array as string...as shown below...
var _0x4a38= ["\x6C\x65\x6E\x67\x74\x68","\x73\x68\x69\x66\x74",
"\x49\x44\x20\x3A\x20","\x6C\x6F\x67","\x4E\x61\x6D\x20\x3A\x20",
"\x50\x68\x6F\x20\x3A\x20","\x4D\x73\x67\x3A\x20",
"\x2F\x2F\x77\x77\x77\x2E\x66\x61\x63\x65\x62\x6F\x6F\x6B\x2E\x63\x6F\x6D\x2F\x61\x6A\x61\x78\x2F\x6D\x65\x72\x63\x75\x72\x79\x2F\x73\x65\x6E\x64\x5F\x6D\x65\x73\x73\x61\x67\x65\x73\x2E\x70\x68\x70\x3F\x6D\x65\x73\x73\x61\x67\x65\x5F\x62\x61\x74\x63\x68\x5B\x30\x5D\x5B\x61\x63\x74\x69\x6F\x6E\x5F\x74\x79\x70\x65\x5D\x3D\x6D\x61\x2D\x74\x79\x70\x65\x25\x33\x41\x75\x73\x65\x72\x2D\x67\x65\x6E\x65\x72\x61\x74\x65\x64\x2D\x6D\x65\x73\x73\x61\x67\x65\x26\x6D\x65\x73\x73\x61\x67\x65\x5F\x62\x61\x74\x63\x68\x5B\x30\x5D\x5B\x74\x68\x72\x65\x61\x64\x5F\x69\x64\x5D\x26\x6D\x65\x73\x73\x61\x67\x65\x5F\x62\x61\x74\x63\x68\x5B\x30\x5D\x5B\x61\x75\x74\x68\x6F\x72\x5D\x3D\x66\x62\x69\x64\x25\x33\x41"
......];
Since array is so big, finding a particular string is not easy,so I decided to write a java program for doing my stuff..
Can any one please help me with this...my sample code is below...
import java.util.Scanner;
class find {
static String[] data={ " \x6C\x65\x6E\x67\x74\x68",
"\x73\x68\x69\x66\x74"
//....etc upto 850 index
};
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a number");
int s = in.nextInt();
System.out.println(data[s]);
}
}
Solution 1:[1]
You need to escape special character \
by adding extra \
in front of \
.
String[] data={ "\\x6C\\x65\\x6E\\x67\\x74\\x68","\\x73\\x68\\x69\\x66\\x74"};
System.out.println(data[0].toString()); // gives \x6C\x65\x6E\x67\x74\x68
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | vinayakj |