Results 1 to 9 of 9
  1. #1
    mastercrimson is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default for Loop with Yes/No Question! help..please!

    Wer i can put my next code if i press "Y" the program will proceed to the next day of loop and i can not enter Time in and Time out but if i Press "N".. i can continue enter Timein and Timeout then proceed to the next day of loop?
    Please help!!!


    This is my codes....

    Java Code:
    import java.io.*;
    
    public class DayLoop
    {
    public static void main(String[]args) throws Exception
    {
    BufferedReader read = new BufferedReader (new InputStreamReader(System.in));
    String empDays[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
    String holiday="";
    int tin=0,tout=0;
    
    
    for (int cnt=0;cnt<empDays.length;cnt++)
    {
    System.out.println("=======================");
    System.out.println("Today is " +empDays[cnt]);
    System.out.println("=======================");
    System.out.print("Is "+empDays[cnt]);
    System.out.println(" a Holiday? Y/N");
    holiday = read.readLine();
    System.out.println("***********************");
    System.out.println("Enter Time-in: ");
    tin = Integer.parseInt(read.readLine());
    System.out.println("Enter Time-out: ");
    tout = Integer.parseInt(read.readLine());
    
    }
    
    }
    
    }
    Last edited by Eranga; 05-31-2010 at 05:16 PM. Reason: code tags added

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Maybe you should go to the basics tutorial: http://java.sun.com/docs/books/tutor...lts/index.html

    Java Code:
    for (int cnt=0;cnt<empDays.length;cnt++)
    {
      System.out.println("=======================");
      System.out.println("Today is " +empDays[cnt]);
      System.out.println("=======================");
      System.out.print("Is "+empDays[cnt]);
      System.out.println(" a Holiday? Y/N");
      holiday = read.readLine();
      if(holiday.equals("Y")){
        System.out.println("***********************");
        System.out.println("Enter Time-in: ");
        tin = Integer.parseInt(read.readLine());
        System.out.println("Enter Time-out: ");
        tout = Integer.parseInt(read.readLine());
      }
    }
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    808
    Rep Power
    6

    Default

    as phHein told,u do...apat from this u just add this holiday.trim().equalsIgnoreCase() to be safe
    Ramya:cool:

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    as phHein told,u do...apat from this u just add this holiday.trim().equalsIgnoreCase() to be safe
    To remove trailing and leading spaces as well as ignore the case sensitivity. :cool:

  5. #5
    mastercrimson is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default That's Good

    But i need more inputs if i press "N" in keyboard the program will continues and i start enter time-in and time-out...

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by mastercrimson View Post
    But i need more inputs if i press "N" in keyboard the program will continues and i start enter time-in and time-out...
    Confusing! Do you want to continue the process both options, yes and no?

  7. #7
    mastercrimson is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default

    nope., i mean if i press "Y" the program will go to next day of loop and i can not enter time in and time out but if I press "N" the program will continue entering time in and time out...

    Thanks in Advance masters...

  8. #8
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    305
    Rep Power
    6

    Default

    Sounds like you should figure out what phHein did and just reverse it.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by StormyWaters View Post
    Sounds like you should figure out what phHein did and just reverse it.
    Yeah, so that he really doesn't really understood what happen in if(holiday.equals("Y")){

Similar Threads

  1. Replies: 5
    Last Post: 04-30-2010, 05:05 PM
  2. Question about for loop..
    By sivakumar_sakam in forum New To Java
    Replies: 4
    Last Post: 05-15-2009, 11:23 PM
  3. How to loop a question when answer is negatve?
    By brazuca in forum New To Java
    Replies: 6
    Last Post: 04-23-2009, 05:46 AM
  4. nested for loop question
    By javabob in forum New To Java
    Replies: 3
    Last Post: 05-20-2008, 11:00 PM
  5. Question regarding foreach loop...
    By theonlywalks in forum New To Java
    Replies: 2
    Last Post: 03-15-2008, 06:15 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •