คืนค่าการตั้งค่าทั้งหมด
คุณแน่ใจว่าต้องการคืนค่าการตั้งค่าทั้งหมด ?
ลำดับตอนที่ #1 : ลำดับตอนที่ 1
import java.util.*;
import sun.misc.Queue;
public class MidB49540461 {
public static void main(String[] args) throws InterruptedException {
Scanner console = new Scanner(System.in);
System.out.println("Choosse '1' or '2' to action:");
int choice = 0;
choice = console.nextInt();
if (choice == 1) {
System.out.print("x = ");
int x = 0;
x = console.nextInt();
System.out.print("n = ");
int n = 0;
n = console.nextInt();
one(x, n);
} else if (choice == 2) {
System.out.print("Enter a string: ");
String palin = "";
palin = console.next();
two(palin);
} else {
System.out.println("Invalid choice!!!");
}
}
private static void one(int x, int n) {
int answer = 0;
answer = recursiveone(x, n);
System.out.println("Answer = " + answer);
}
private static int recursiveone(int x, int n) {
int answer = 0;
if (x == 0 || n == 0) {
return 1;
} else if (x > 0 && n > 0) {
answer = (2 * x) * recursiveone(x, n - 1);
} else if (x < 0) {
answer = (2 * x) * recursiveone(x, n - 1);
}
return answer;
}
private static void two(String palin) throws InterruptedException {
Stack<Character> stack = new Stack<Character>();
Queue myqueue = new Queue();
char[] asd = new char[palin.length()];
for (int k = 0; k < palin.length(); k++) {
asd[k] = palin.charAt(k);
if (asd[k] == 'a' || asd[k] == 'b' || asd[k] == 'c'
|| asd[k] == 'd' || asd[k] == 'e' || asd[k] == 'f'
|| asd[k] == 'g' || asd[k] == 'h' || asd[k] == 'i'
|| asd[k] == 'j' || asd[k] == 'k' || asd[k] == 'l'
|| asd[k] == 'n' || asd[k] == 'o' || asd[k] == 'i'
|| asd[k] == 'p' || asd[k] == 's' || asd[k] == 'q'
|| asd[k] == 'w' || asd[k] == 'r' || asd[k] == 'x'
|| asd[k] == 'y' || asd[k] == 'u' || asd[k] == 'z') {
break;
} else {
System.out.println("Invalid!");
System.exit(0);
}
}
System.out.println("It include characters.");
for (int i = 0; i < palin.length(); i++) {
stack.push(palin.charAt(i));
myqueue.enqueue(palin.charAt(i));
}
String ans1 = "", ans2 = "";
for (int j = 0; j < palin.length(); j++) {
if (stack.pop() != myqueue.dequeue()) {
ans2 = "NO.";
} else {
ans1 = "YES.";
}
}
if (ans2.equals("NO.")) {
System.out.println(ans2);
} else {
System.out.println(ans1);
}
}
}
ความคิดเห็น