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

Thread: please help first program

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please help first program

    I started learning java today and this is my first program I made without copying from tutorials. It works but there are some glitches. It's supposed to check lottery numbers. One of the glitches I know is when I enter 1, 2, 3, 4, 5, 6 and 7 the first one is than supposed to be 1 but for a strange reason it's 5+ please help me.


    import java.util.Scanner;
     
    class lotto{
    	public static void main(String args[]){
    		Scanner sam = new Scanner(System.in);	
    		int S1N1, S1N2, S1N3, S1N4, S1N5, S1N6;
    		int S2N1, S2N2, S2N3, S2N4, S2N5, S2N6;
    		int S3N1, S3N2, S3N3, S3N4, S3N5, S3N6;
    		int S4N1, S4N2, S4N3, S4N4, S4N5, S4N6;
    		int S5N1, S5N2, S5N3, S5N4, S5N5, S5N6;
    		int S6N1, S6N2, S6N3, S6N4, S6N5, S6N6;
    		int N1, N2, N3, N4, N5, N6, NE;
    		double S1, S2, S3, S4, S5, S6;
    		String S1T, S2T, S3T, S4T, S5T, S6T;
     
    		S1N1 = 7;
    		S1N2 = 11;
    		S1N3 = 16;
    		S1N4 = 21;
    		S1N5 = 24;
    		S1N6 = 28;
     
    		S2N1 = 4;
    		S2N2 = 21;
    		S2N3 = 24;
    		S2N4 = 28;
    		S2N5 = 40;
    		S2N6 = 44;
     
    		S3N1 = 6;
    		S3N2 = 15;
    		S3N3 = 17;
    		S3N4 = 26;
    		S3N5 = 34;
    		S3N6 = 38;
     
    		S4N1 = 5;
    		S4N2 = 7;
    		S4N3 = 8;
    		S4N4 = 22;
    		S4N5 = 33;
    		S4N6 = 35;
     
    		S5N1 = 9;
    		S5N2 = 17;
    		S5N3 = 21;
    		S5N4 = 31;
    		S5N5 = 35;
    		S5N6 = 39;
     
    		S6N1 = 2;
    		S6N2 = 6;
    		S6N3 = 18;
    		S6N4 = 29;
    		S6N5 = 30;
    		S6N6 = 38;
     
     
    		S1 = 0;
    		S2 = 0;
    		S3 = 0;
    		S4 = 0;
    		S5 = 0;
    		S6 = 0;
     
    		S1T = "1: Je hebt 0 juiste.";
    		S2T = "2: Je hebt 0 juiste.";
    		S3T = "3: Je hebt 0 juiste.";
    		S4T = "4: Je hebt 0 juiste.";
    		S5T = "5: Je hebt 0 juiste.";
    		S6T = "6: Je hebt 0 juiste.";
    		System.out.println("Eerste nummer:");
    		N1 = sam.nextInt();
    		System.out.println("Tweede nummer:");
    		N2 = sam.nextInt();
    		System.out.println("Derde nummer:");
    		N3 = sam.nextInt();
    		System.out.println("Vierde nummer:");
    		N4 = sam.nextInt();
    		System.out.println("Vijfde nummer:");
    		N5 = sam.nextInt();
    		System.out.println("Zesde nummer:");
    		N6 = sam.nextInt();
    		System.out.println("Reserve nummer:");
    		NE = sam.nextInt();
     
    		if (N1 == S1N1 || N1 == S1N2 || N1 == S1N3 || N1 == S1N4 || N1 == S1N5 || N1 == S1N6){
    			S1 += 1;
    		}
    		if (N2 == S1N1 || N2 == S1N2 || N2 == S1N3 || N2 == S1N4 || N2 == S1N5 || N2 == S1N6){
    			S1 += 1;
    		}
    		if (N3 == S1N1 || N3 == S1N2 || N3 == S1N3 || N3 == S1N4 || N3 == S1N5 || N3 == S1N6){
    			S1 += 1;
    		}
    		if (N4 == S1N1 || N4 == S1N2 || N4 == S1N3 || N4 == S1N4 || N4 == S1N5 || N4 == S1N6){
    			S1 += 1;
    		}
    		if (N5 == S1N1 || N5 == S1N2 || N5 == S1N3 || N5 == S1N4 || N5 == S1N5 || N5 == S1N6){
    			S1 += 1;
    		}
    		if (N6 == S1N1 || N6 == S1N2 || N6 == S1N3 || N6 == S1N4 || N6 == S1N5 || N6 == S1N6){
    			S1 += 1;
    		}
    		if (S1 == 5 && NE == S1N1 || NE == S1N2 || NE == S1N3 || NE == S1N4 || NE == S1N5 || NE == S1N6){
    			S1 = 5.5;
    		}
    		if (S1 == 1){
    			S1T = "1: Je hebt 1 juiste.";
    		}
    		if (S1 == 2){
    			S1T = "1: Je hebt 2 juiste.";
    		}
    		if (S1 == 3){
    			S1T = "1: Je hebt 3 juiste.";
    		}
    		if (S1 == 4){
    			S1T = "1: Je hebt 4 juiste.";
    		}
    		if (S1 == 5){
    			S1T = "1: Je hebt 5 juiste.";
    		}
    		if (S1 == 6){
    			S1T = "1: Je hebt 6 juiste!";
    		}
    		if (S1 == 5.5){
    			S1T = "1: Je hebt 5+ juiste.";
    		}
    		if (N1 == S2N1 || N1 == S2N2 || N1 == S2N3 || N1 == S2N4 || N1 == S2N5 || N1 == S2N6){
    			S2 += 1;
    		}
    		if (N2 == S2N1 || N2 == S2N2 || N2 == S2N3 || N2 == S2N4 || N2 == S2N5 || N2 == S2N6){
    			S2 += 1;
    		}
    		if (N3 == S2N1 || N3 == S2N2 || N3 == S2N3 || N3 == S2N4 || N3 == S2N5 || N3 == S2N6){
    			S2 += 1;
    		}
    		if (N4 == S2N1 || N4 == S2N2 || N4 == S2N3 || N4 == S2N4 || N4 == S2N5 || N4 == S2N6){
    			S2 += 1;
    		}
    		if (N5 == S2N1 || N5 == S2N2 || N5 == S2N3 || N5 == S2N4 || N5 == S2N5 || N5 == S2N6){
    			S2 += 1;
    		}
    		if (N6 == S2N1 || N6 == S2N2 || N6 == S2N3 || N6 == S2N4 || N6 == S2N5 || N6 == S2N6){
    			S2 += 1;
    		}
    		if (S2 == 5 && NE == S2N1 || NE == S2N2 || NE == S2N3 || NE == S2N4 || NE == S2N5 || NE == S2N6){
    			S2 = 5.5;
    		}
    		if (S2 == 1){
    			S2T = "2: Je hebt 1 juiste.";
    		}
    		if (S2 == 2){
    			S2T = "2: Je hebt 2 juiste.";
    		}
    		if (S2 == 3){
    			S2T = "2: Je hebt 3 juiste.";
    		}
    		if (S2 == 4){
    			S2T = "2: Je hebt 4 juiste.";
    		}
    		if (S2 == 5){
    			S2T = "2: Je hebt 5 juiste.";
    		}
    		if (S2 == 6){
    			S2T = "2: Je hebt 6 juiste!";
    		}
    		if (S2 == 5.5){
    			S2T = "2: Je hebt 5+ juiste.";
    		}
    		if (N1 == S3N1 || N1 == S3N2 || N1 == S3N3 || N1 == S3N4 || N1 == S3N5 || N1 == S3N6){
    			S3 += 1;
    		}
    		if (N2 == S3N1 || N2 == S3N2 || N2 == S3N3 || N2 == S3N4 || N2 == S3N5 || N2 == S3N6){
    			S3 += 1;
    		}
    		if (N3 == S3N1 || N3 == S3N2 || N3 == S3N3 || N3 == S3N4 || N3 == S3N5 || N3 == S3N6){
    			S3 += 1;
    		}
    		if (N4 == S3N1 || N4 == S3N2 || N4 == S3N3 || N4 == S3N4 || N4 == S3N5 || N4 == S3N6){
    			S3 += 1;
    		}
    		if (N5 == S3N1 || N5 == S3N2 || N5 == S3N3 || N5 == S3N4 || N5 == S3N5 || N5 == S3N6){
    			S3 += 1;
    		}
    		if (N6 == S3N1 || N6 == S3N2 || N6 == S3N3 || N6 == S3N4 || N6 == S3N5 || N6 == S3N6){
    			S3 += 1;
    		}
    		if (S3 == 5 && NE == S3N1 || NE == S3N2 || NE == S3N3 || NE == S3N4 || NE == S3N5 || NE == S3N6){
    			S3 = 5.5;
    		}
    		if (S3 == 1){
    			S3T = "3: Je hebt 1 juiste.";
    		}
    		if (S3 == 2){
    			S3T = "3: Je hebt 2 juiste.";
    		}
    		if (S3 == 3){
    			S3T = "3: Je hebt 3 juiste.";
    		}
    		if (S3 == 4){
    			S3T = "3: Je hebt 4 juiste.";
    		}
    		if (S3 == 5){
    			S3T = "3: Je hebt 5 juiste.";
    		}
    		if (S3 == 6){
    			S3T = "3: Je hebt 6 juiste!";
    		}
    		if (S3 == 5.5){
    			S3T = "3: Je hebt 5+ juiste.";
    		}
    		if (N1 == S4N1 || N1 == S4N2 || N1 == S4N3 || N1 == S4N4 || N1 == S4N5 || N1 == S4N6){
    			S4 += 1;
    		}
    		if (N2 == S4N1 || N2 == S4N2 || N2 == S4N3 || N2 == S4N4 || N2 == S4N5 || N2 == S4N6){
    			S4 += 1;
    		}
    		if (N3 == S4N1 || N3 == S4N2 || N3 == S4N3 || N3 == S4N4 || N3 == S4N5 || N3 == S4N6){
    			S4 += 1;
    		}
    		if (N4 == S4N1 || N4 == S4N2 || N4 == S4N3 || N4 == S4N4 || N4 == S4N5 || N4 == S4N6){
    			S4 += 1;
    		}
    		if (N5 == S4N1 || N5 == S4N2 || N5 == S4N3 || N5 == S4N4 || N5 == S4N5 || N5 == S4N6){
    			S4 += 1;
    		}
    		if (N6 == S4N1 || N6 == S4N2 || N6 == S4N3 || N6 == S4N4 || N6 == S4N5 || N6 == S4N6){
    			S4 += 1;
    		}
    		if (S4 == 5 && NE == S4N1 || NE == S4N2 || NE == S4N3 || NE == S4N4 || NE == S4N5 || NE == S4N6){
    			S4 = 5.5;
    		}
    		if (S4 == 1){
    			S4T = "4: Je hebt 1 juiste.";
    		}
    		if (S4 == 2){
    			S4T = "4: Je hebt 2 juiste.";
    		}
    		if (S4 == 3){
    			S4T = "4: Je hebt 3 juiste.";
    		}
    		if (S4 == 4){
    			S4T = "4: Je hebt 4 juiste.";
    		}
    		if (S4 == 5){
    			S4T = "4: Je hebt 5 juiste.";
    		}
    		if (S4 == 6){
    			S4T = "4: Je hebt 6 juiste!";
    		}
    		if (S4 == 5.5){
    			S4T = "4: Je hebt 5+ juiste.";
    		}
    		if (N1 == S5N1 || N1 == S5N2 || N1 == S5N3 || N1 == S5N4 || N1 == S5N5 || N1 == S5N6){
    			S5 += 1;
    		}
    		if (N2 == S5N1 || N2 == S5N2 || N2 == S5N3 || N2 == S5N4 || N2 == S5N5 || N2 == S5N6){
    			S5 += 1;
    		}
    		if (N3 == S5N1 || N3 == S5N2 || N3 == S5N3 || N3 == S5N4 || N3 == S5N5 || N3 == S5N6){
    			S5 += 1;
    		}
    		if (N4 == S5N1 || N4 == S5N2 || N4 == S5N3 || N4 == S5N4 || N4 == S5N5 || N4 == S5N6){
    			S5 += 1;
    		}
    		if (N5 == S5N1 || N5 == S5N2 || N5 == S5N3 || N5 == S5N4 || N5 == S5N5 || N5 == S5N6){
    			S5 += 1;
    		}
    		if (N6 == S5N1 || N6 == S5N2 || N6 == S5N3 || N6 == S5N4 || N6 == S5N5 || N6 == S5N6){
    			S5 += 1;
    		}
    		if (S5 == 5 && NE == S5N1 || NE == S5N2 || NE == S5N3 || NE == S5N4 || NE == S5N5 || NE == S5N6){
    			S5 = 5.5;
    		}
    		if (S5 == 1){
    			S5T = "5: Je hebt 1 juiste.";
    		}
    		if (S5 == 2){
    			S5T = "5: Je hebt 2 juiste.";
    		}
    		if (S5 == 3){
    			S5T = "5: Je hebt 3 juiste.";
    		}
    		if (S5 == 4){
    			S5T = "5: Je hebt 4 juiste.";
    		}
    		if (S5 == 5){
    			S5T = "5: Je hebt 5 juiste.";
    		}
    		if (S5 == 6){
    			S5T = "5: Je hebt 6 juiste!";
    		}
    		if (S5 == 5.5){
    			S5T = "5: Je hebt 5+ juiste.";
    		}
    		if (N1 == S6N1 || N1 == S6N2 || N1 == S6N3 || N1 == S6N4 || N1 == S6N5 || N1 == S6N6){
    			S6 += 1;
    		}
    		if (N2 == S6N1 || N2 == S6N2 || N2 == S6N3 || N2 == S6N4 || N2 == S6N5 || N2 == S6N6){
    			S6 += 1;
    		}
    		if (N3 == S6N1 || N3 == S6N2 || N3 == S6N3 || N3 == S6N4 || N3 == S6N5 || N3 == S6N6){
    			S6 += 1;
    		}
    		if (N4 == S6N1 || N4 == S6N2 || N4 == S6N3 || N4 == S6N4 || N4 == S6N5 || N4 == S6N6){
    			S6 += 1;
    		}
    		if (N5 == S6N1 || N5 == S6N2 || N5 == S6N3 || N5 == S6N4 || N5 == S6N5 || N5 == S6N6){
    			S6 += 1;
    		}
    		if (N6 == S6N1 || N6 == S6N2 || N6 == S6N3 || N6 == S6N4 || N6 == S6N5 || N6 == S6N6){
    			S6 += 1;
    		}
    		if (S6 == 5 && NE == S6N1 || NE == S6N2 || NE == S6N3 || NE == S6N4 || NE == S6N5 || NE == S6N6){
    			S6 = 5.5;
    		}
    		if (S6 == 1){
    			S6T = "6: Je hebt 1 juiste.";
    		}
    		if (S6 == 2){
    			S6T = "6: Je hebt 2 juiste.";
    		}
    		if (S6 == 3){
    			S6T = "6: Je hebt 3 juiste.";
    		}
    		if (S6 == 4){
    			S6T = "6: Je hebt 4 juiste.";
    		}
    		if (S6 == 5){
    			S6T = "6: Je hebt 5 juiste.";
    		}
    		if (S6 == 6){
    			S6T = "6: Je hebt 6 juiste!";
    		}
    		if (S6 == 5.5){
    			S6T = "6: Je hebt 5+ juiste.";
    		}
    		System.out.println(S1T);
    		System.out.println(S2T);
    		System.out.println(S3T);
    		System.out.println(S4T);
    		System.out.println(S5T);
    		System.out.println(S6T);
    	}
    }


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: please help first program

    I don't think anybody is going to look at your code until you rewrite it using at worst arrays (if not some simple classes of your own) and meaningful variable names. Consider writing a LotteryNumber class so you can write something like
    LotteryNumber lotNum = new LotteryNumber(7, 11, 16, 21, 24, 28);
    You could then declare an array of winning numbers like
    LotteryNumber[] winningNumbers =
     new LotteryNumber[]{new LotteryNumber(blah blah), new Lotterblah...};
    and use a for loop and overriding the 'equals()' method in LotteryNumber to test your own numbers to see if you've won.

    It's a lot easier to write working Java applications if you write something that looks like Java. Your program should only be about 20-30 lines long.

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help first program

    I'm sorry but as I said I started learning today and I have no idea how I do all that I just wanted to know why it didn't work.

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Location
    toronto
    Posts
    14
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: please help first program

    is it your first time? then.. read some basic java posts... and please at least explain what you wanna do in your code and what is errors more..

  5. #5
    Junior Member
    Join Date
    Jul 2011
    Location
    toronto
    Posts
    14
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: please help first program

    and i run your program and i got '1: Je hebt 0 juiste.'
    what do you mean by 'it is supposed to be 1 not +5'?

    there is no 1 in your variables....

Similar Threads

  1. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM