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: Will my program work every time?

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

    Exclamation Will my program work every time?

    package venko;

    import java.util.Scanner;

    public class peshev {
    public static void main(String[] args) {
    int vodki;
    Scanner sc = new Scanner(System.in);
    System.out.print("Kolko vodki e izpil Alex? ");
    vodki = sc.nextInt();
    System.out.println();
    if(vodki > 3 && vodki < 9) {
    System.out.println("Ivetka ot Pravec zamina");
    }
    else if(vodki >= 9){ System.out.println("Aleks povrushta");
    }
    else if(vodki <= 3) {System.out.println("Ivetka ne e ebana.Alex ne e dostatuchno piqn");
    }
    }
    }

  2. #2
    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: Will my program work every time?

    I do not understand your problem. Please explain in more detail.

    Please edit your post and wrap your code with code tags:

    [code]
    **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.

  3. #3
    Member
    Join Date
    Jun 2022
    Posts
    41
    Thanks
    1
    Thanked 3 Times in 2 Posts

    Default Re: Will my program work every time?


    yes it considers each of the three ranges.

    If the program falls through all three if statements, then maybe variable vodki = null. But if vodki = null, then if statements would cause exception. So better to test for null first.

Similar Threads

  1. daily time record & computation of hours work
    By cess in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 14th, 2014, 02:42 AM
  2. Need Help With First Time Program
    By UnrealOl1ve in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 1st, 2014, 08:03 AM
  3. Replies: 1
    Last Post: September 9th, 2013, 11:26 AM
  4. Having a hard time figuring out how to make my code work
    By iainnitro in forum Loops & Control Statements
    Replies: 2
    Last Post: September 6th, 2011, 07:48 AM
  5. [SOLVED] How much time should I have on a program?
    By SOG in forum Java Theory & Questions
    Replies: 17
    Last Post: July 19th, 2011, 05:28 PM

Tags for this Thread