Home In java, is there a way to combine String.contain() and String.equals() to print out a certain character when given another?
Reply: 0

In java, is there a way to combine String.contain() and String.equals() to print out a certain character when given another?

user1330
1#
user1330 Published in April 22, 2018, 3:07 am

I was working on some java code that prints out "secret code" when you input a certain phrase. ("Hello" would print "itssg", a=q, b=w, c=e, etc)

I got through part of it only to realize I can't use String.contain() or String.equals() if I want the corresponding letters printed out.

Is there someway to combine the two to make the letters match up to the secret code?

Here's part of the code:

String r = JOptionPane.showInputDialog(null,
  "Enter the text you want to be turned into secret code.\n\n The secret code will print out at the bottom of your screen.");

if ("A".equals(r) || "a".equals(r)) {
 System.out.print("q");
} else {}

if ("B".equals(r) || "b".equals(r)) {
 System.out.print("w");
} else {}

if ("C".equals(r) || "c".equals(r)) {
 System.out.print("e");
} else {}
if ("D".equals(r) || "d".equals(r)) {
 System.out.print("r");
}

if ("E".equals(r) || "e".equals(r)) {
 System.out.print("t");
}

if ("F".equals(r) || "f".equals(r)) {
 System.out.print("y");
}

if ("G".equals(r) || "g".equals(r)) {
 System.out.print("u");
}

if ("H".equals(r) || "h".equals(r)) {
 System.out.print("i");
}

if ("I".equals(r) || "i".equals(r)) {
 System.out.print("o");
}

if ("J".equals(r) || "j".equals(r)) {
 System.out.print("p");
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303512 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO