Jump to content

Welcome to NulledBlog
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!
Photo

Need help with code


  • Please log in to reply
2 replies to this topic

#1
Jimmyboi

  • Offline
  • Le Pleb

  • Posts:
    872
    Reputation:
    44
    Joined:
    12 Dec, 2015

Hey, I am making lottery program but code is messed up when I need to input my numbers. How can I fix this? I don't want to use arrays

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lotodomaci;
 
/**
 *
 * @author USER
 */
import java.util.*;
public class LotoDomaci {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      boolean vrednost=false;
        int randomBroj1;
        int randomBroj2;
        int randomBroj3;
        int randomBroj4;
        int randomBroj5;
        int randomBroj6;
        int randomBroj7;
        
            Scanner ulaz=new Scanner(System.in);
            System.out.println("Pravila: Ispisite 7 razlicitih brojeva od 0 do 39 i ako se poklope sa nasim brojevima, vi ste dobitnik. Srecno!");
//these are just some rules up here ^
//PokusaniBroj is number that I need to put in
          int PokusaniBroj1;
          int PokusaniBroj3;
          int PokusaniBroj4;
          int PokusaniBroj5;
          int PokusaniBroj6;
          int PokusaniBroj7;
          int PokusaniBroj2;
            int k=0;
            System.out.print("Unesite prvi broj:");
//put in the first number ^
            do { 
                if (k==1){
                    System.out.print("Pogresan broj uneti ponovo:");
 //Wrong number, try again ^
                }
                else System.out.println("Unesite drugi broj");
            PokusaniBroj1=ulaz.nextInt();
            k=1;
            }  
            while( PokusaniBroj1>39 || PokusaniBroj1<0);
                do { 
                if (k==1){
                    System.out.print("Pogresan broj uneti ponovo:");
                }
                else System.out.println("Unesite treci broj");
            PokusaniBroj2=ulaz.nextInt();
            k=1;
            
            }while( PokusaniBroj2>39 || PokusaniBroj2<0);
            do { 
                if (k==1){
                    System.out.print("Pogresan broj uneti ponovo:");
                }
                else System.out.println("Unesite drugi broj");
            PokusaniBroj3=ulaz.nextInt();
            k=1;
            
            }while( PokusaniBroj3>39 || PokusaniBroj3<0);
                do { 
                if (k==1){
                    System.out.print("Pogresan broj uneti ponovo:");
                }
                else System.out.println("Unesite treci broj");
            PokusaniBroj4=ulaz.nextInt();
            k=1;
            
            }while( PokusaniBroj4>39 || PokusaniBroj4<0);
            do { 
                if (k==1){
                    System.out.print("Pogresan broj uneti ponovo:");
                }
                else System.out.println("Unesite drugi broj");
            PokusaniBroj5=ulaz.nextInt();
            k=1;
            
            }while( PokusaniBroj5>39 || PokusaniBroj5<0);
                do { 
                if (k==1){
                    System.out.print("Pogresan broj uneti ponovo:");
                }
                else System.out.println("Unesite treci broj");
            PokusaniBroj6=ulaz.nextInt();
            k=1;
            
            }while( PokusaniBroj6>39 || PokusaniBroj6<0);
            do { 
                if (k==1){
                    System.out.print("Pogresan broj uneti ponovo:");
                }
                else System.out.println("Unesite treci broj");
            PokusaniBroj7=ulaz.nextInt();
            k=1;
            
            }while( PokusaniBroj7>39 || PokusaniBroj7<0);
      //from here everything is ok
               randomBroj1=(int)(39*Math.random())+1;
       randomBroj2=(int)(39*Math.random())+1;
       randomBroj3=(int)(39*Math.random())+1;
       randomBroj4=(int)(39*Math.random())+1;
       randomBroj5=(int)(39*Math.random())+1;
       randomBroj6=(int)(39*Math.random())+1;
       randomBroj7=(int)(39*Math.random())+1;
    
       while(vrednost==false){
       randomBroj1=(int)(39*Math.random())+1;
       randomBroj2=(int)(39*Math.random())+1;
       randomBroj3=(int)(39*Math.random())+1;
       randomBroj4=(int)(39*Math.random())+1;
       randomBroj5=(int)(39*Math.random())+1;
       randomBroj6=(int)(39*Math.random())+1;
       randomBroj7=(int)(39*Math.random())+1;
           
        if (randomBroj1!=randomBroj2
                &&randomBroj1!=randomBroj3
                &&randomBroj1!=randomBroj4
                &&randomBroj1!=randomBroj5
                &&randomBroj1!=randomBroj6
                &&randomBroj1!=randomBroj7
                &&randomBroj2!=randomBroj3
                &&randomBroj2!=randomBroj4
                &&randomBroj2!=randomBroj5
                &&randomBroj2!=randomBroj6
                &&randomBroj2!=randomBroj7
                &&randomBroj3!=randomBroj4
                &&randomBroj3!=randomBroj5
                &&randomBroj3!=randomBroj6
                &&randomBroj3!=randomBroj7
                &&randomBroj4!=randomBroj5
                &&randomBroj4!=randomBroj6
                &&randomBroj4!=randomBroj7
                &&randomBroj5!=randomBroj6
                &&randomBroj5!=randomBroj7
                &&randomBroj6!=randomBroj7)
            
        {
           
            System.out.println("Brojevi su"
                    +"..."
                    +randomBroj1+"..."
                    +randomBroj2+"..."
                    +randomBroj3+"..."
                    +randomBroj4+"..."
                    +randomBroj5+"..."
                    +randomBroj6+"..."
                    +randomBroj7);
           vrednost=true;
           
            }
       
       }
       
 
       if (randomBroj1==PokusaniBroj1&&
               randomBroj2==PokusaniBroj2&&
                       randomBroj3==PokusaniBroj3&&
                       randomBroj4==PokusaniBroj4&&
                       randomBroj5==PokusaniBroj5&&
                       randomBroj6==PokusaniBroj6&&
                       randomBroj7==PokusaniBroj7){
           System.out.println("DOBILI STE MILION EVRA!!!");
       }
       else System.out.println("Nazalost niste pobedili u ovoj igri, pokusajte ponovo");
         
       }
        
    }
 

  • 0

You can donate to me here - 1PyyEHZ7SADWLcnktdMU7SNLXX5rskjFvs


#2
huydth1999

  • Offline
  • New Member

  • PipPip
  • Posts:
    24
    Reputation:
    10
    Joined:
    22 Dec, 2015

thank you for all :D


  • 0

#3
4sy

  • Offline
  • Member

  • Posts:
    31
    Reputation:
    0
    Joined:
    23 Mar, 2016

I think it's better using the array for a clean e simple code. If you can translate all the program in English I can give u a little help.


  • 0


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users