Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package assignments;
- import java.util.*;
- public class StringUtil {
- static String stringOne;
- public StringUtil(){
- @SuppressWarnings("resource")
- Scanner in = new Scanner(System.in);
- System.out.print("Enter your String:");
- stringOne = in.nextLine();
- }
- public void backwards (String backward){
- StringBuffer buffer = new StringBuffer(backward);
- buffer = buffer.reverse();
- backward = buffer.toString();
- System.out.println("The Word Backwards:"+backward);
- }
- public void check(String string3){
- StringBuffer buffer = new StringBuffer(string3);
- buffer = buffer.reverse();
- String string4 = buffer.toString();
- if(string3.equals(string4)){
- System.out.println("TRUE");
- }
- else
- System.out.println("FALSE");
- }
- public static void main(String[]args){
- StringUtil word = new StringUtil();
- word.backwards(stringOne);
- word.check(stringOne);
- }
- }
- //Anirudh Maddula
- package assignments;
- public class RomanNumerals {
- public static void rome(int roman){
- if(4000>roman || roman > 0){
- if(roman >= 1000){
- int M = roman/1000;
- if(M == 4){
- System.out.print("MMMM");
- rome(roman-4000);
- }
- if(M == 3){
- System.out.print("MMM");
- rome(roman-3000);
- }
- if(M == 2){
- System.out.print("MM");
- rome(roman-2000);
- }
- if(M == 1){
- System.out.print("M");
- rome(roman-1000);
- }
- }
- if(roman >= 500){
- int D = roman/500;
- if (D == 1){
- System.out.print("D");
- rome(roman-500);
- }
- }
- if(roman >= 100){
- int C = roman/100;
- if (C == 4){
- System.out.print("CD");
- rome(roman-400);
- }
- if (C == 3){
- System.out.print("CCC");
- rome(roman-300);
- }
- if (C == 2){
- System.out.print("CC");
- rome(roman-200);
- }
- if (C == 1){
- System.out.print("C");
- rome(roman-100);
- }
- }
- if(roman >= 50){
- int L = roman/50;
- if(L == 1){
- System.out.print("L");
- rome(roman-50);
- }
- }
- if(roman >= 10){
- int X = roman/10;
- if (X == 1){
- System.out.print("X");
- rome(roman-10);
- }
- if (X == 2){
- System.out.print("XX");
- rome(roman-20);
- }
- if (X == 3){
- System.out.print("XXX");
- rome(roman-30);
- }
- if(X == 4){
- System.out.print("XL");
- rome(roman-40);
- }
- }
- if(roman >= 5){
- int V = roman/5;
- if(V == 1){
- System.out.print("V");
- rome(roman-5);
- }
- }
- if(roman >= 1){
- int I = roman/1;
- if(I == 1){
- System.out.print("I");
- rome(roman-1);
- }
- if(I == 2){
- System.out.print("II");
- rome(roman-2);
- }
- if(I == 3){
- System.out.print("III");
- rome(roman-3);
- }
- if(I == 4){
- System.out.print("IV");
- rome(roman-4);
- }
- }
- }
- else
- System.out.println("I'm Sorry, Dave, I can't Answer That Question.");
- return;
- }
- public static void arabic(String arab){
- System.out.println("Enter the Roman Numerals One Grouping At A Time.");
- int mil = 0;
- int cent = 0;
- int dec = 0;
- int demi = 0;
- int dix = 0;
- int hand = 0;
- int uno = 0;
- if(arab.contains(" MMMM ")){
- mil = 4000;
- }
- if(arab.contains(" MMM ")){
- mil = 3000;
- }
- if(arab.contains(" MM ")){
- mil = 2000;
- }
- if(arab.contains(" M ")){
- mil = 1000;
- }
- if(arab.contains(" D ")){
- demi = 500;
- }
- if(arab.contains(" CD ")){
- cent = 400;
- }
- if(arab.contains(" CCC ")){
- cent = 300;
- }
- if(arab.contains(" CC ")){
- cent = 200;
- }
- if(arab.contains(" C ")){
- cent = 100;
- }
- if(arab.contains(" L ")){
- dec = 50;
- }
- if(arab.contains(" XL ")){
- dix = 40;
- }
- if(arab.contains(" XXX ")){
- dix = 30;
- }
- if(arab.contains(" XX ")){
- dix = 20;
- }
- if(arab.contains(" X ")){
- dix = 10;
- }
- if(arab.contains(" V ")){
- hand = 5;
- }
- if(arab.contains(" IV ")){
- uno = 4;
- }
- if(arab.contains(" III ")){
- uno = 3;
- }
- if(arab.contains(" II ")){
- uno = 2;
- }
- if(arab.contains(" I ")){
- uno = 1;
- }
- System.out.println("");
- System.out.println("Arabic Value of Roman Numerals: " + (uno+dix+demi+cent+mil+dec+hand));
- }
- public static void main(String[] args) {
- RomanNumerals.rome(1234);
- RomanNumerals.arabic(" M CC XXX IV ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement