Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   indentifier expected (http://www.programmingforums.org/showthread.php?t=11873)

akbomber Nov 13th, 2006 9:28 PM

indentifier expected
 
i am a noob at java so my problem could quite possibly be really easy to fix
what im trying to do is get it so for a day in January it will display the day of week sunday being 0 and i keep gettin an identifier expected error

:

import java.util.Scanner;

public class DayOfWeek
{
        String dayName;
        public int dayOfWeek1(int day);
        {
                dayOfWeek1 = (day - 1) % 7;
                return dayOfWeek1;
        }
       
        public static void main(String[] args)
        {
                Scanner kb = new Scanner(System.in);
                System.out.println("Enter Day in January (1-31): ");
                int day = kb.nextInt();
               
                if(dayOfWeek1 = 0)
                {
                        dayName = "Sunday";
                }
                if(dayOfWeek1 = 1)
                {
                        dayName = "Monday";
                }
                if(dayOfWeek1 = 2)
                {
                        dayName = "Tuesday";
                }
                if(dayOfWeek1 = 3)
                {
                        dayName = "Wednesday";
                }
                if(dayofWeek1 = 4)
                {
                        dayName = "Thursday";
                }
                if(dayOfWeek1 = 5)
                {
                        dayName = "Friday";
                }
                if(dayOfWeek1 = 6)
                {
                        dayName = "Saturday";
                }
               
        }
       
        system.out.println(dayName);       
       
               
}


DaWei Nov 13th, 2006 9:56 PM

dayOfWeek1 is a function, not a variable. Break out your parentheses and toss in a couple, along with an argument.

The Dark Nov 13th, 2006 10:01 PM

Also this line:
:

        system.out.println(dayName);
Needs to be inside a function.

akbomber Nov 13th, 2006 10:03 PM

lol like i said i am a complete noob
can u plz describe wut u mean more by that
both of u id prob understand wut ur saying but i just dont no wut u mean by function and such

DaWei Nov 13th, 2006 10:06 PM

Break out the book. Maybe you could even find one written in AOL-speak, so you could understand it.

akbomber Nov 13th, 2006 10:11 PM

i love you to

Arevos Nov 14th, 2006 2:42 AM

Before you learn how to program in a language, there is really a minimum of information you should know before asking questions. In Java, this is a class:
:

  1. class DayOfWeek
  2. {
  3. }

This is the definition of a function, also known as a method:
:

  1. String fooey(String s)
  2. {
  3.     return s + "? Fooey!";
  4. }

This method takes in a string as input, and returns a string as output. In Java, all methods have to be defined inside a class. This is a variable:
:

  1. String name = "Churchill";

Variables can be defined in a class, or in a method. This is a method call:
:

  1. System.out.println("Hello World");

Generally speaking, a method call should be called from another method. The method with the name "main" will be called automatically when the program starts.

However, I'm not sure why I'm writing this, because there are far better places to learn the basics. Honestly, it's like asking why your car isn't working, and then asking simple questions like, "Tyre? What's a 'tyre'?". We can't help you if you don't know the absolute basics.

Also, it helps if you speak using as good English as you can manage. This shows you're taking the effort to be understood, which encourages other people to take some effort to help you. If you can't be bothered to string together a valid sentence, why should people be bothered helping you? Also, programming languages typically require the programmer to strictly adhere to the syntax of the language. It might help for you to start practising on English, first.

And if you're wondering why I'm saying this after I gave you some basic information; it's because I'm a helpful imbecile. However, even my patience has it's limits.

akbomber Nov 14th, 2006 7:37 AM

ok there you go i know what a method is i had not ever heard the term function before

DaWei Nov 14th, 2006 8:08 AM

OK, there you go. I know what a method is. I had never heard the term, function, before.

stevengs Nov 14th, 2006 5:04 PM

I was wondering what a term sounds like when it functions. Does it make a sound when it functions in a forest where there is no one to hear it?


All times are GMT -5. The time now is 10:06 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC