Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import java.util.Stack;
  2. import java.util.Scanner;
  3.  
  4. public class Pennie {
  5.  
  6. public static void main(String[] args) {
  7. // TODO Auto-generated method stub
  8. Scanner sc = new Scanner(System.in);
  9. Stack<String> st = new Stack<String>();
  10. while (true) {
  11. String S = sc.nextLine();
  12. if (S.equals("SCHOOL")) {
  13. break;
  14. }
  15. st.add(S);
  16. }
  17.  
  18. while (true) {
  19. String D = st.pop(); //read the last one
  20. if (st.isEmpty()) {
  21. if (D.equals("R")) {
  22. System.out.println("Turn LEFT into your HOME.");
  23. } else {
  24. System.out.println("Turn RIGHT into your HOME.");
  25. }
  26. break;
  27. } else {
  28. String street = st.pop() ;
  29. if (D.equals("R")) {
  30. System.out.println("Turn LEFT onto "+street+" street.");
  31. } else {
  32. System.out.println("Turn RIGHT onto "+street+" street.");
  33. }
  34. }
  35. }
  36.  
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement