Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. package assignments;
  2. import java.util.*;
  3.  
  4. public class StringUtil {
  5. static String stringOne;
  6. public StringUtil(){
  7. @SuppressWarnings("resource")
  8. Scanner in = new Scanner(System.in);
  9. System.out.print("Enter your String:");
  10. stringOne = in.nextLine();
  11. }
  12. public void backwards (String backward){
  13. StringBuffer buffer = new StringBuffer(backward);
  14. buffer = buffer.reverse();
  15. backward = buffer.toString();
  16. System.out.println("The Word Backwards:"+backward);
  17. }
  18.  
  19. public void check(String string3){
  20. StringBuffer buffer = new StringBuffer(string3);
  21. buffer = buffer.reverse();
  22. String string4 = buffer.toString();
  23. if(string3.equals(string4)){
  24. System.out.println("TRUE");
  25. }
  26. else
  27. System.out.println("FALSE");
  28. }
  29.  
  30. public static void main(String[]args){
  31. StringUtil word = new StringUtil();
  32. word.backwards(stringOne);
  33.  
  34. word.check(stringOne);
  35. }
  36. }
  37.  
  38. //Anirudh Maddula
  39.  
  40. package assignments;
  41.  
  42. public class RomanNumerals {
  43. public static void rome(int roman){
  44. if(4000>roman || roman > 0){
  45. if(roman >= 1000){
  46. int M = roman/1000;
  47. if(M == 4){
  48. System.out.print("MMMM");
  49. rome(roman-4000);
  50. }
  51. if(M == 3){
  52. System.out.print("MMM");
  53. rome(roman-3000);
  54. }
  55. if(M == 2){
  56. System.out.print("MM");
  57. rome(roman-2000);
  58. }
  59. if(M == 1){
  60. System.out.print("M");
  61. rome(roman-1000);
  62. }
  63. }
  64. if(roman >= 500){
  65. int D = roman/500;
  66. if (D == 1){
  67. System.out.print("D");
  68. rome(roman-500);
  69. }
  70. }
  71. if(roman >= 100){
  72. int C = roman/100;
  73. if (C == 4){
  74. System.out.print("CD");
  75. rome(roman-400);
  76. }
  77. if (C == 3){
  78. System.out.print("CCC");
  79. rome(roman-300);
  80. }
  81. if (C == 2){
  82. System.out.print("CC");
  83. rome(roman-200);
  84. }
  85. if (C == 1){
  86. System.out.print("C");
  87. rome(roman-100);
  88. }
  89. }
  90. if(roman >= 50){
  91. int L = roman/50;
  92. if(L == 1){
  93. System.out.print("L");
  94. rome(roman-50);
  95. }
  96. }
  97. if(roman >= 10){
  98. int X = roman/10;
  99. if (X == 1){
  100. System.out.print("X");
  101. rome(roman-10);
  102. }
  103. if (X == 2){
  104. System.out.print("XX");
  105. rome(roman-20);
  106. }
  107. if (X == 3){
  108. System.out.print("XXX");
  109. rome(roman-30);
  110. }
  111. if(X == 4){
  112. System.out.print("XL");
  113. rome(roman-40);
  114. }
  115. }
  116. if(roman >= 5){
  117. int V = roman/5;
  118. if(V == 1){
  119. System.out.print("V");
  120. rome(roman-5);
  121. }
  122. }
  123. if(roman >= 1){
  124. int I = roman/1;
  125. if(I == 1){
  126. System.out.print("I");
  127. rome(roman-1);
  128. }
  129. if(I == 2){
  130. System.out.print("II");
  131. rome(roman-2);
  132. }
  133. if(I == 3){
  134. System.out.print("III");
  135. rome(roman-3);
  136. }
  137. if(I == 4){
  138. System.out.print("IV");
  139. rome(roman-4);
  140. }
  141. }
  142. }
  143. else
  144. System.out.println("I'm Sorry, Dave, I can't Answer That Question.");
  145. return;
  146. }
  147. public static void arabic(String arab){
  148. System.out.println("Enter the Roman Numerals One Grouping At A Time.");
  149. int mil = 0;
  150. int cent = 0;
  151. int dec = 0;
  152. int demi = 0;
  153. int dix = 0;
  154. int hand = 0;
  155. int uno = 0;
  156. if(arab.contains(" MMMM ")){
  157. mil = 4000;
  158. }
  159. if(arab.contains(" MMM ")){
  160. mil = 3000;
  161. }
  162. if(arab.contains(" MM ")){
  163. mil = 2000;
  164. }
  165. if(arab.contains(" M ")){
  166. mil = 1000;
  167. }
  168. if(arab.contains(" D ")){
  169. demi = 500;
  170. }
  171. if(arab.contains(" CD ")){
  172. cent = 400;
  173. }
  174. if(arab.contains(" CCC ")){
  175. cent = 300;
  176. }
  177. if(arab.contains(" CC ")){
  178. cent = 200;
  179. }
  180. if(arab.contains(" C ")){
  181. cent = 100;
  182. }
  183. if(arab.contains(" L ")){
  184. dec = 50;
  185. }
  186. if(arab.contains(" XL ")){
  187. dix = 40;
  188. }
  189. if(arab.contains(" XXX ")){
  190. dix = 30;
  191. }
  192. if(arab.contains(" XX ")){
  193. dix = 20;
  194. }
  195. if(arab.contains(" X ")){
  196. dix = 10;
  197. }
  198. if(arab.contains(" V ")){
  199. hand = 5;
  200. }
  201. if(arab.contains(" IV ")){
  202. uno = 4;
  203. }
  204. if(arab.contains(" III ")){
  205. uno = 3;
  206. }
  207. if(arab.contains(" II ")){
  208. uno = 2;
  209. }
  210. if(arab.contains(" I ")){
  211. uno = 1;
  212. }
  213.  
  214. System.out.println("");
  215. System.out.println("Arabic Value of Roman Numerals: " + (uno+dix+demi+cent+mil+dec+hand));
  216. }
  217. public static void main(String[] args) {
  218. RomanNumerals.rome(1234);
  219. RomanNumerals.arabic(" M CC XXX IV ");
  220. }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement