Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Problem with day of month code

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with day of month code

    I have an assignment where I'm supposed to write a program where the user inputs a month between 1-12 and then the right amount number in every month. I've tweaked the code a bunch of times, but I keep getting this error message:

    insert "}" to complete Statement KALENDER_3.java
    insert "}" to complete Block KALENDER_3.java

    The code:

    import java.util.*;
    import java.util.Scanner;

    public class KALENDER_3

    }

    public static void main(String[] args){
    Scanner scanner = new Scanner (System.in);
    System.out.print("Skriv ett månadsnummer: ");

    int månad = scanner.nextInt();
    if (månad < 1 || månad > 12) {
    System.out.print("Det finns ingen månad " + månad + ". Skriv igen");
    } else {
    System.out.print("Skriv vilken dag inom månaden: ");

    // JAG BÖRJAR MED MÅNADEN, JAG SKAPAR EN SCANNER SOM GÖR ATT JAG KAN LÄSA AV VARIABELN "MÅNAD"
    // SEDAN SKAPAR JAG ETT IF/ELSE FÖR HUR MÅNGA MÅNADER SOM MAN KAN SKRIVA MELLAN

    int dag = scanner.nextInt();

    //SEDAN SKAPAR JAG EN VARIABEL FÖR "DAG" KOMMANDOT,
    //EFTER DETTA BÖRJAR JAG GÖRA IF/ELSE FÖR VARJE MÅNAD SAMT ANTAL DAGAR

    if (månad == 1) {
    if (dag < 1 || dag > 31) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else {
    System.out.print("Rätt datum!"); }

    //FEBRUARI
    if (månad == 2) {
    if (dag < 1 || dag > 28) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else {
    System.out.print("Rätt datum!");
    //MARS
    if (månad == 3) {
    if (dag < 1 || dag > 31) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else {
    System.out.print("Rätt datum!");
    //APRIL
    if (månad == 4) {
    if (dag < 1 || dag > 30) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else {
    System.out.print("Rätt datum!");


    //MAJ
    if (månad == 5) {
    if (dag < 1 || dag > 31) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else {
    System.out.print("Rätt datum!");
    //JUNI
    if (månad == 6) {
    if (dag < 1 || dag > 30) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else {
    System.out.print("Rätt datum!");
    //JULI
    if (månad == 7) {
    if (dag < 1 || dag > 31) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else {
    System.out.print("Rätt datum!");
    //AUGUSTI
    if (månad == 8) {
    if (dag < 1 || dag > 31) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else {
    System.out.print("Rätt datum!");
    //SEPTEMBER
    if (månad == 9) {
    if (dag < 1 || dag > 30) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else {
    System.out.print("Rätt datum!");
    //OKTOBER
    if (månad == 10) {
    if (dag < 1 || dag > 31) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else {
    System.out.print("Rätt datum!");
    //NOVEMBER
    if (månad == 11) {
    } if (dag < 1 || dag > 30) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else {
    System.out.print("Rätt datum!"); }
    //DECEMBER
    if (månad == 12){
    }if (dag < 1 || dag > 31) {
    System.out.print("Månad " + månad + " har ingen dag " + dag + ".");
    } else{
    System.out.print("Rätt datum!");

    {



    I think I have just forgot to put in a few { } symbols, maybe an open loop? I can't figure it out. Can you see it?

    (The comments and quote strings are in swedish in case you are confused by them, I've also removed some of them for easier reading.)


  2. #2
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: Problem with day of month code

    Well the last curly brace you have there is an opening. The last one should always be a closed braces. My advice would be to look through the code carefully and make sure that all if and else statements have matching curly braces. Put it in an IDE and auto indent/format it to make it easier to read.
    Last edited by camel-man; September 21st, 2014 at 01:19 PM.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problem with day of month code

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Program to check how many people are born on the same day of the month
    By ksahakian21 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 6th, 2012, 02:11 PM
  2. Resetting a Variable on a Day of the Month
    By HarleyRowland in forum Java Theory & Questions
    Replies: 1
    Last Post: October 15th, 2012, 10:36 AM
  3. problem Comparing date and month from dates
    By desire7696 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 6th, 2012, 10:08 AM
  4. Array month/day/hour/min/sec incomplete java code
    By mightyking in forum Collections and Generics
    Replies: 12
    Last Post: September 18th, 2011, 08:46 PM
  5. Day,Month,Year Concatenation Error
    By srinivasan_253642 in forum JDBC & Databases
    Replies: 1
    Last Post: January 22nd, 2010, 04:40 AM