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 4 of 4

Thread: Hi, i have a simple question.

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hi, i have a simple question.

    Hi,
    I have this code in my main :
    public static void main(String[] args)
    	{
    		final int Sunday = 1;
    		final int Monday = 2;
    		final int Tuesday = 3;
    		final int Wendesday = 4;
    		final int Thursday = 5;
    		final int Friday = 6;
    		final int Saturday = 7;
     
    		int num;
    		Scanner scan = new Scanner(System.in);
     
    		System.out.println("What is the day today?");
    		num = scan.nextInt();
    		switch(num)
    		{
    		case 0 : System.out.println("The day is " + Sunday);
    		break;
    		case 1 : System.out.println("The day is " + Monday);
    		break;
    		case 2 : System.out.println("The day is " + Tuesday);
    		break;
    		case 3 : System.out.println("The day is " + Wendesday);
    		break;
    		case 4 : System.out.println("The day is " + Thursday);
    		break;
    		case 5 : System.out.println("The day is " + Friday);
    		break;
    		case 6 : System.out.println("The day is " + Saturday);
    		break;
    		}
     
     
    	}

    I want that all the days (Sunday , Monday, etc) will print me the day "Sunday", not a int, how can i do it?
    Thanks,
    Or.


  2. #2
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Hi, i have a simple question.

    Quote Originally Posted by oror84 View Post
    Hi,
    I want that all the days (Sunday , Monday, etc) will print me the day "Sunday", not a int, how can i do it?
    Thanks,
    Or.
    Hello oror84!
    Can you explain what are you trying to do?
    If you want to print every "Sunday" time you can just add it inside the " "'s.
    But if you want to evaluate the user's input and display the appropriate day you will need a different approach.
    Hope it helps.

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

    Default Re: Hi, i have a simple question.

    Change this:
    System.out.println("The day is " + Sunday);
    to this
    System.out.println("The day is Sunday");
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hi, i have a simple question.

    Alright I see your problem. Your problem is this.

    all your final int (weekday) = number.

    when you put a weekday into a system.out its always going to give a number... because you set it as a number.

    System.out.println("Today is " + Sunday) is always going to output "Today is 1" because you have Sunday set to a value of 1.

Similar Threads

  1. Simple Question (I Think...?)
    By srwoltering in forum Object Oriented Programming
    Replies: 3
    Last Post: March 22nd, 2012, 02:56 PM
  2. Simple I/O Question...well could be simple for you?
    By basketball8533 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 30th, 2011, 06:44 AM
  3. Simple question
    By white97 in forum Java Theory & Questions
    Replies: 1
    Last Post: August 11th, 2011, 06:30 PM
  4. Help with a simple question
    By allea in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 28th, 2011, 07:46 AM
  5. not so simple, simple swing question box
    By wolfgar in forum AWT / Java Swing
    Replies: 2
    Last Post: November 20th, 2009, 03:47 AM