0

I am converting the English date into the Welsh date using a Java program but the if statements do not appear to run as the date does not change. What am I doing wrong?

I am new to Java and I have learnt Python and am now teaching myself Java. This English-to-Welsh date converter was a task I set myself in Python and I have now set it for Java.

Code:

import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        System.out.println("What is the Date?:");
        Scanner date = new Scanner (System.in);
        String Date = date.next();
        date.nextLine();
        System.out.println("What Day is it?:");
        Scanner day = new Scanner (System.in);
        String Day = day.next();
        day.nextLine();
        System.out.println("What Month is it?:");
        Scanner month = new Scanner (System.in);
        String Month = month.next();
        month.nextLine();
        if (Day == "Monday"){
            Day = "Dydd Llun";
        }
        if (Day == "Tuesday"){
            Day = "Dydd Mawrth";
        }
        if (Day == "Wednesday"){
            Day = "Dydd Mercher";
        }
        if (Day == "Thursday"){
            Day = "Dydd Iau";
        }
        if (Day == "Friday"){
            Day = "Dydd Gwener";
        }
        if (Day == "Saturday"){
            Day = "Dydd Sadwrn";
        }
        if (Day == "Sunday"){
            Day = "Dydd Sul";
        }
        if (Month == "January"){
            Month = "Ionawr";
        }
        if (Month == "Febuary"){
            Month = "Chwefror";
        }
        if (Month == "March"){
            Month = "Mawrth";
        }

        if (Month == "April"){
            Month = "Ebrill";
        }
        if (Month == "May"){
            Month = "Mai";
        }
        if (Month == "June"){
            Month = "Mehefin";
        }
        if (Month == "Jully"){
            Month = "Gorffennaf";
        }
        if (Month == "August"){
            Month = "Awst";
        }
        if (Month == "September"){
            Month = "Medi";
        }
        if (Month == "October"){
            Month = "Hydref";
        }
        if (Month == "November"){
            Month = "Tachwedd";
        }
        if (Month == "December"){
            Month = "Rhagfyr";
        }
        System.out.println(Date + " " + Day + " " + Month);
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dylan.evans007
  • 113
  • 2
  • 10
  • Aside from Strings comparison problem, don't create many Scanner isntances. Create one and reuse it like `Scanner sc = new Scanner(System.in); String date = sc.next(); String month = sc.next(); ...`. – Pshemo Jun 17 '15 at 22:31
  • @Pshemo It isn't a comparison problem the print statement is running before the if statements – Dylan.evans007 Jun 17 '15 at 22:37
  • Use .equals instead of ==. Like Day.equals("Monday") to check for equality – lakshayg Jun 17 '15 at 22:45
  • It works fine for me if I correct your way of comparing strings and will use only one Scanner: http://ideone.com/CeRezd – Pshemo Jun 17 '15 at 22:46
  • @Pshemo Thanks for your help! The program is working now. – Dylan.evans007 Jun 17 '15 at 22:57

0 Answers0