자바 배열 선언

언어/java2016. 5. 16. 20:15



자바 특징 : 초기화가 자동적으로 된다. 숫자 0으로

배열 선언 int[] Arr_Name = new int[SIZE];


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

자바 에러날때  (0) 2016.05.17
import java.util.Scanner;  (0) 2016.05.16
java if문  (0) 2016.05.16
stu1 (python vs ruby vs go  (0) 2016.02.14
java [ 구구단 ]  (0) 2016.02.11

java if문

언어/java2016. 5. 16. 20:06


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

import java.util.Scanner;  (0) 2016.05.16
자바 배열 선언  (0) 2016.05.16
stu1 (python vs ruby vs go  (0) 2016.02.14
java [ 구구단 ]  (0) 2016.02.11
자바로 로또 구현중(계속 업데이트해야함) ver0.1  (0) 2016.01.23

package stu;
import java.util.Scanner;
public class stu2 {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
       
        int value1, value2;
       
        //[1] value1 input ---------------------------
        System.out.print("value1 input >>>  ");
        value1 = input.nextInt();
        //[2] value2 input ---------------------------
        System.out.print("value2 input >>>  ");
        value2 = input.nextInt();
       
        if(value1 == value2) {
            System.out.printf("value1[%d] == value2[%d] \n", value1, value2);
        } else if(value1 > value2) {
            System.out.printf("value1[%d] > value2[%d]  \n" , value1, value2);
        } else {
            System.out.printf("value1[%d] < value2[%d]  \n" , value1, value2);
        }
       
    }
}



import random
'''
value_1_typeOf_integer = int(input("value_1_typeOf_integer >>> "))
value_2_typeOf_integer = int(input("value_2_typeOf_integer >>> "))
'''
case_1_summation = 0
case_2_summation = 0
case_3_summation = 0
count_number_typeOf_integer = 0

while(True):
#----- variable -------------------------------
value_1_typeOf_integer = random.randint(1, 10)
value_2_typeOf_integer = random.randint(1, 10)
count_number_typeOf_integer += 1
#-----------------------------------------------

#[1] value1 == value2
if (value_1_typeOf_integer == value_2_typeOf_integer):
print("[{0:d}] {1:d} == {2:d}"\
.format(count_number_typeOf_integer,value_1_typeOf_integer, value_2_typeOf_integer))
case_1_summation +=1
#[2] value1 > value2
elif (value_1_typeOf_integer > value_2_typeOf_integer):
print("[{0:d}] {1:d} > {2:d}"\
.format(count_number_typeOf_integer,value_1_typeOf_integer, value_2_typeOf_integer))
case_2_summation +=1
#[3] value1 < value2
else:
print("[{0:d}] {1:d} < {2:d}"\
.format(count_number_typeOf_integer,value_1_typeOf_integer, value_2_typeOf_integer))
case_3_summation +=1
if (count_number_typeOf_integer == 300): break
#end

print("case_1: {0:.2f}% -> {1:3d}/300".format(float(case_1_summation)/300, case_1_summation))
print("case_2: {0:.2f}% -> {1:3d}/300".format(float(case_2_summation)/300, case_2_summation))
print("case_3: {0:.2f}% -> {1:3d}/300".format(float(case_3_summation)/300, case_3_summation))



print("value1_integer input >>>   ")
number_1_int = gets.chomp.to_i

print("value2_integer input >>> ")
number_2_int = gets.chomp.to_i

if(number_1_int == number_2_int)
print("#{number_1_int} == #{number_2_int}")
elsif(number_1_int > number_2_int)
print("#{number_1_int} > #{number_2_int}")
else
print("#{number_1_int} < #{number_2_int}")
end


package main

import "fmt"
import "math/rand"

func main() {
//------ variable setting ------
var value1_integer int
var value2_integer int

case_1:=0
case_2:=0
case_3:=0
count:= 0
//------------------------------------

for {
value1_integer=rand.Intn(10)+1
value2_integer=rand.Intn(10)+1
count +=1
// case [1]
if value1_integer == value2_integer {
fmt.Printf("[%3d] %d == %d \n", count, value1_integer, value2_integer)
case_1 += 1

// case [2]
} else if value1_integer > value2_integer {
fmt.Printf("[%3d] %d > %d \n", count, value1_integer, value2_integer)
case_2 += 1

// case [3]
} else {
fmt.Printf("[%3d] %d < %d \n", count, value1_integer, value2_integer)
case_3 += 1
}

if count == 300 {
break
}
}// END
fmt.Printf("case_1: [%.2f] --> [%d/300] \n", float32(case_1)/300, case_1)
fmt.Printf("case_2: [%.2f] --> [%d/300] \n", float32(case_2)/300, case_2)
fmt.Printf("case_3: [%.2f] --> [%d/300] \n", float32(case_3)/300, case_3)
}


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

자바 배열 선언  (0) 2016.05.16
java if문  (0) 2016.05.16
java [ 구구단 ]  (0) 2016.02.11
자바로 로또 구현중(계속 업데이트해야함) ver0.1  (0) 2016.01.23
2016 01 18  (0) 2016.01.18

java [ 구구단 ]

언어/java2016. 2. 11. 22:01
public class gugudan {
public static void main(String[] args) {
int indexi, indexj;
for (indexi = 2; indexi<= 9; indexi++) {
for (indexj = 1; indexj<=9; indexj++) {
System.out.printf("%d x %d = %d \t", indexi, indexj, indexi*indexj);
if (indexj == 9) {
System.out.printf("\n");
}
}
}
}
}


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

java if문  (0) 2016.05.16
stu1 (python vs ruby vs go  (0) 2016.02.14
자바로 로또 구현중(계속 업데이트해야함) ver0.1  (0) 2016.01.23
2016 01 18  (0) 2016.01.18
(java) 삼각형 형성조건  (0) 2016.01.18

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

2016 01 18

언어/java2016. 1. 18. 22:34

package shift;
import java.util.Scanner;
public class stu6 {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner input = new Scanner(System.in);
  int arr_2[] = {50,100};
  int x_y_2[] = new int[2];
  System.out.print("점(x,y)의 좌표를 입력하시오>> ");
  x_y_2[0] = input.nextInt();
  x_y_2[1] = input.nextInt();
  if((x_y_2[0]>=arr_2[0] && x_y_2[0]<=arr_2[1]) &&
     (x_y_2[1]>=arr_2[0] && x_y_2[1]<=arr_2[1]))
  {
   System.out.println("사각형 안에 점이 있습니다.");
  }
  else
  {
   System.out.println("사각형 안에 점이 없습니다.");
  }
 }
}

 

package shift;
import java.util.Scanner;
public class stu4 {
 public static int test=0;
 public static void main(String[] args){
 Scanner input = new Scanner(System.in);
 int arr_3[] = new int[3];
 for(int i=0; i<3; i++)
 {
  System.out.printf("[%d]번째 데이터 입력: ", i+1);
  arr_3[i] = input.nextInt();
  if(arr_3[i] == 0)
   while(true)
   {
    System.out.print("0은 입력할 수 없습니다. 다시 입력해주세요:  ");
    arr_3[i] = input.nextInt();
    if(arr_3[i] != 0)break;
   }
    }
 rearrange_bubble_sort(arr_3, 3);
 for(int i=0; i<3; i++)
 {
  System.out.print(arr_3[i]);
  System.out.printf("\t");
 }
 triangle_test(arr_3, 3);
 
}
public static void rearrange_bubble_sort(int arr[], int n)
{
 int i,j,temp;
 
 for(i=0; i<=n-1; i++)
 {  
  for(j=0; j<n-1; j++)
  {   
   if(arr[j]>arr[j+1])
   {
    
    temp = arr[j];
    arr[j] = arr[j+1];
    arr[j+1] = temp;
   }
  }
 }
}
public static void triangle_test(int arr[], int n)
{
 if(arr[0]+ arr[1] > arr[n-1])
 {
  System.out.println("삼각형을 만들 수 있습니다.\n");
 }
 if(arr[0]+ arr[1] <= arr[n-1])
 {
  System.out.println("삼각형을 만들 수 없습니다.\n");
 }
}
}

 

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

자바로 로또 구현중(계속 업데이트해야함) ver0.1  (0) 2016.01.23
2016 01 18  (0) 2016.01.18
수정할 것 (재귀함수 호출 공부 코드); 계속해서 갱신해볼 것  (0) 2016.01.18
2016-01-18  (0) 2016.01.18
2016-01-18  (0) 2016.01.18

package shift;
import java.util.Scanner;
public class stu4 {
 public static int test=0;
 public static void main(String[] args){
 Scanner input = new Scanner(System.in);
 int arr_3[] = new int[3];
 for(int i=0; i<3; i++)
 {
  System.out.printf("[%d]번째 데이터 입력: ", i+1);
  arr_3[i] = input.nextInt();
  if(arr_3[i] == 0)
  {
   while(true)
   {
    System.out.print("0은 입력할 수 없습니다. 다시 입력해주세요:  ");
    arr_3[i] = input.nextInt();
    if(arr_3[i] == 0)
    {
     
    }
    }
     }
  
    }
 test(arr_3,0,1,2);
 
}
public static void test(int arr[],int start, int end, int remaind)
{
 int temp;
 if((arr[start]+arr[end])>arr[remaind])
 {
  System.out.println(test);
  System.out.printf("%d 와 (과) %d 에 의해 삼각형이 형성됩니다.\n"
    , arr[start],arr[end]);
  return;
 }
 else
 {
  if(test == 7)
  {
   System.out.println(test);
   System.out.printf("삼각형이 형성될 수 없는 조건 입니다.\n");
   return;
  }
  temp = end;
  end = remaind;
  remaind = temp;
  test = test+1;
  test(arr,start,end,remaind);
  }
 }
}

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

2016 01 18  (0) 2016.01.18
(java) 삼각형 형성조건  (0) 2016.01.18
2016-01-18  (0) 2016.01.18
2016-01-18  (0) 2016.01.18
st1  (0) 2015.10.26

2016-01-18

언어/java2016. 1. 18. 00:42

package shift;
import java.util.Scanner;
public class stu3 {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  String add = "12345-67890";
  Scanner input = new Scanner

 

 

 

(add).useDelimiter("\\s|-");
  

System.out.print(input.next());
 }

}

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

2016 01 18  (0) 2016.01.18
(java) 삼각형 형성조건  (0) 2016.01.18
수정할 것 (재귀함수 호출 공부 코드); 계속해서 갱신해볼 것  (0) 2016.01.18
2016-01-18  (0) 2016.01.18
st1  (0) 2015.10.26

2016-01-18

언어/java2016. 1. 18. 00:25

package shift;
import java.util.Scanner;
public class stu2 {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  //a->97, z->122 
  //A->65, Z->90
  Scanner input = new Scanner(System.in);
  char a = input.next().charAt(0);
  
  if((int)a >=97  && (int)a<=122)
  {
   System.out.printf("입력하신 문자는 %c 정수값은 %d\n", a, (int)a);
   System.out.printf("소문자 [%c] -> 대문자 [%c]\n", a, a-32);
  }
  else if((int)a >=65  && (int)a<=90)
  {
   System.out.printf("입력하신 문자는 %c 정수값은 %d\n", a, (int)a);
   System.out.printf("대문자 [%c] -> 소문자 [%c]\n", a, a+32);
  }
  else
  {
   System.out.println("영문자가 아닙니다.");
  }
   
 }

}

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

2016 01 18  (0) 2016.01.18
(java) 삼각형 형성조건  (0) 2016.01.18
수정할 것 (재귀함수 호출 공부 코드); 계속해서 갱신해볼 것  (0) 2016.01.18
2016-01-18  (0) 2016.01.18
st1  (0) 2015.10.26