package stu;
import java.util.Scanner;
class Number{
 public int[] number = new int[45];
 public int[] win_number = new int[45];
 Number()//생성자
 {
  for(int i=0; i<number.length; i++)
  {
   this.number[i] = i+1;
  }
 }
 public void PrintF()
 {
  for(int i=0; i<number.length; i++)
  {
   System.out.printf("[%d] ",this.number[i]);
  }
  System.out.println();
 }
 public void win_Lotto()
 {
  int k;
  int SetNum=45;
  int temp;
  for(int i=0; i<7; i++){
   k = (int)(Math.random()*SetNum);
   this.win_number[i] = this.number[k];
   for(int j=k; j<number.length-1; j++)
   {
    this.number[j] = this.number[j+1];
   }
   SetNum--;
  }
  for(int i=6; i>=0; i--){
   for(int j=0; j<i; j++){
    if( this.win_number[j]> this.win_number[j+1])
    {
     temp = this.win_number[j];
     this.win_number[j] = this.win_number[j+1];
     this.win_number[j+1] = temp;
    }
   }
  }
  
  System.out.println("<<<<< 당첨번호 >>>>>");
  for(int i=0; i<7; i++){
   System.out.printf("[%2d]", this.win_number[i]);
  }
  System.out.println();
 }
}//class Number

public class LOTTO extends Number{
 //******************* MAIN FUNCTION *******************
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner input = new Scanner(System.in);
  Number lotto = new Number();
  lotto.win_Lotto();
  random_ball();
  choice();
 }
 //******************* MAIN FUNCTION *******************
 
 //******************* FUNCTION 1 *******************
 //로또 7자리 숫자를 랜덤으로 SORTING
 public static int[] random_ball()
 {
  int k;
  int SetNum=45;
  int temp;
  int[] Temp_Setting_Lotto = new int[45];
  for(int s=0; s<Temp_Setting_Lotto.length; s++){
   Temp_Setting_Lotto[s] = s +1;
  }
  int[] Lotto_Seven = new int[7];
  for(int i=0; i<7; i++){
   k = (int)(Math.random()*SetNum);
   Lotto_Seven[i] = Temp_Setting_Lotto[k];
   for(int j=k; j<Temp_Setting_Lotto.length-1; j++)
   {
    Temp_Setting_Lotto[j] = Temp_Setting_Lotto[j+1];
   }
   SetNum--;
  }
  for(int i=6; i>=0; i--){
   for(int j=0; j<i; j++){
    if( Lotto_Seven[j]> Lotto_Seven[j+1])
    {
     temp = Lotto_Seven[j];
     Lotto_Seven[j] = Lotto_Seven[j+1];
     Lotto_Seven[j+1] = temp;
    }
   }
  }
  
  System.out.println("<<<<< Random_Choice >>>>>");
  for(int i=0; i<7; i++){
   System.out.printf("[%2d]", Lotto_Seven[i]);
  }
  System.out.println();
  return Lotto_Seven;
 }
 
 //******************* FUNCTION 2 *******************
 //로또 7자리 숫자를 입력, SORTING
 public static void choice()
 {
  Scanner input = new Scanner(System.in);
  int temp;
  int s;
  int choice = 0;
  int[] Lotto_Seven = new int[7];
  for(int k=0; k<7; k++)
  {   
   System.out.printf("[%d]번째 번호 입력>>> ",k+1);
   while(true)
   {
    Lotto_Seven[k] = input.nextInt();
    if(Lotto_Seven[k]<1 || Lotto_Seven[k]>45)
    {
     System.out.print("잘못입력하셨습니다. 다시입력: ");
     Lotto_Seven[k] = input.nextInt();
    }
    else//(Lotto_Seven[k]>=1 && Lotto_Seven[k]<==45)
    {
     for(int j=0; j<k; j++){
      if(Lotto_Seven[k] == Lotto_Seven[j])
      {
       System.out.println("겹치는 숫자가 존재. 다시입력: ");
       choice = 1;
       break;
      }
      else
      {
       choice = 0;
      }
     }
    }
    if(choice == 0)
    {
     break;
    }
   }
  }
  for(int i=6; i>=0; i--){
   for(int j=0; j<i; j++){
    if( Lotto_Seven[j]> Lotto_Seven[j+1])
    {
     temp = Lotto_Seven[j];
     Lotto_Seven[j] = Lotto_Seven[j+1];
     Lotto_Seven[j+1] = temp;
    }
   }
  }
  
  System.out.println("<<<<< Random_Choice >>>>>");
  for(int i=0; i<7; i++){
   System.out.printf("[%2d]", Lotto_Seven[i]);
  }
  System.out.println();
 }
}

'언어 > java' 카테고리의 다른 글

stu1 (python vs ruby vs go  (0) 2016.02.14
java [ 구구단 ]  (0) 2016.02.11
2016 01 18  (0) 2016.01.18
(java) 삼각형 형성조건  (0) 2016.01.18
수정할 것 (재귀함수 호출 공부 코드); 계속해서 갱신해볼 것  (0) 2016.01.18