public class Test {

    public static void main(String args[]) {

    //배열 0~5

    int temp = 0;

    int num[] = {10, 5, 7, 20, 4, 2};

   

    for(int i=0; i<=5; i++) {

         for(int j=0; j<=4; j++) {

              if(num[j] < num[j+1]) {

                  temp = num[j];

                  num[j] = num[j+1];

                  num[j+1] = temp;

              }

         }

    }

   

    for(int i=0; i<=5; i++) {

         if(i != 5) {

              System.out.print(num[i] + ",");

         }

         else {

              System.out.print(num[i]);

         }

    }

    }

}


'programing > Java' 카테고리의 다른 글

Servlet 기본 출력  (0) 2018.04.04
Spring frameworkm 개발환경설정  (0) 2018.04.03
점프 투 자바 - 인터페이스  (0) 2018.03.02
점프 투 자바 - 메소드  (0) 2018.02.28
Java - ArrayList  (0) 2018.02.23

File - Invalidate Caches / Restart - Invalidate and Restart 클릭

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jmj.atacadao.MainActivity">

</android.support.constraint.ConstraintLayout>
노란색으로 표시한 부분을 지운 뒤, LinearLayout을 적어준다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jmj.atacadao.MainActivity">

</LinearLayout>


AndroidManifest.xml에 가서 android:theme=~~ 이 부분을 아래와 같이 수정한다.


android:theme="@style/Theme.AppCompat.NoActionBar"


(프로젝트명)\app\src\main\res\mipmap-hdpi

이 폴더에 이미지 넣기


이미지 이름은 첫 글자에 대문자나 숫자 X

소문자_소문자 이렇게 쓰는게 편할 듯 싶다

package com.example.jmj.tutorial3;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

   
private String[] items = {"망고", "딸기", "수박"};

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);

        Button listButton = (Button) findViewById(R.id.
listButton);
        listButton.setOnClickListener(
new View.OnClickListener() {
           
@Override
               
public void onClick(View v){
                    AlertDialog.Builder builder =
new AlertDialog.Builder(MainActivity.this);
                    builder.setTitle(
"리스트");
                    builder.setItems(
items, new DialogInterface.OnClickListener() {
                       
@Override
                        
public void onClick(DialogInterface dialog, int i) {
                            Toast.makeText(getApplicationContext(),
items[i], Toast.LENGTH_SHORT).show();
                        }
                    });

                    AlertDialog alertDialog = builder.create();
                    alertDialog.show();
                }
        });

        Button exitButton  = (Button) findViewById(R.id.
exitButton); //ui에서 id 받아오기
       
exitButton.setOnClickListener(new View.OnClickListener(){
            
@Override
           
public void onClick(View v){
                AlertDialog.Builder builder =
new AlertDialog.Builder(MainActivity.this);
                builder.setMessage(
"종료 ?");
                builder.setTitle(
"종료 알림창")
                        .setCancelable(
false) //3자가 건드리지 못하게 함
                       
.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
                           
@Override
                           
public void onClick(DialogInterface dialog, int i){
                                finish();
                            }
                        })
                        .setNegativeButton(
"No", new DialogInterface.OnClickListener(){
                       
@Override
                       
public void onClick(DialogInterface dialog, int i){
                            dialog.cancel();
                        }
                    });
                AlertDialog alert = builder.create();
                alert.setTitle(
"종료 알림창");
                alert.show();
            }
        });
    }
}

 





출처 : https://www.inflearn.com/course/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-%EC%8A%A4%ED%8A%9C%EB%94%94%EC%98%A4-%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-%EC%95%B1-%EB%A7%8C%EB%93%A4%EA%B8%B0/#course-curriculum


public interface Predator {

       public String getFood(); //인터페이스의 메소드는 메소드의 이름과 입출력에 대한 정의만 있고 내용은 없다.

}



public class Animal {

       String name;

      

       public void setName(String name) {

             this.name = name;

       }

}



public class Tiger extends Animal implements Predator {

       public String getFood() {

             return "apple";

       }

}



public class Tiger extends Animal implements Predator {

       public String getFood() {

             return "apple";

       }

}



public class ZooKeeper {

      

    public void feed(Predator predator) {

        System.out.println("feed " + predator.getFood());

    }

 

 

    public static void main(String[] args) {

        ZooKeeper zooKeeper = new ZooKeeper();

        Tiger tiger = new Tiger();

        Lion lion = new Lion();

        zooKeeper.feed(tiger);

        zooKeeper.feed(lion);

    }

}




출처 : https://wikidocs.net/217


콘솔 출력내용


feed apple

feed banana

참고 사이트 : http://wanna-b.tistory.com/42


File - Settings... - Build, Execution, Deployment - Instant Run - Uncheck : Enable Instant Run


//자바의 함수는 클래스 안에서만 존재 가능 -> 메소드(클래스 내부의 함수)

//메소드 사용 이유 : 똑같은 내용 반복해서 적을 , "어떤 입력값을 주었을 , 어떤 리턴값을 돌려준다"라는 메소드를 작성하여 대신한다.

//출력 = 리턴값

//cf.파이썬은 함수/메소드 별개로 존재     

 

public class Test {

       public int sum(int a, int b) { //sum이라는 메소드는 개의 (int 자료형 a, int 자료형 b) 입력값으로                                       //받으며

             return a+b;              //리턴값은 개의 입력값을 더한 (int 자료형)이다.

       }                              //return 메소드의 결과 값을 돌려주는 명령어이다.

            

       public static void main(String[] args){

             int a = 3;

             int b = 4;

            

             Test myTest = new Test();

             int c = myTest.sum(a, b); //sum메소드에 3, 4라는 입력값을 전달하여 7이라는 값을 돌려받는다.

            

             System.out.print(c);

       }

}




메소드 구조


public 리턴자료형 메소드명(입력자료형1 입력변수1, 입력자료형2 입력변수2, ...){

...

return 리턴값;

}


*리턴자료형이 void면 리턴값 없음

*리턴자료형 public, private, void, static 등

*입력자료형1 입력변수1, 입력자료형2 입력변수2 의 (예시) String name, int a




입력 O 출력 O


public int sum(int a, int b){

     return a+b;

}

public static void main(String[] args) {

     Test myTest = new Test();

     int c = myTest.sum(10, 20);

      

     System.out.print(c);

}


리턴값받을변수 = 객체.메소드명(입력인수1, 입력인수2, ...)


리턴값이 int로 되어있으므로 c의 자료형은 반드시 int로 해야한다. 



입력 X 출력 O


public class Test {

       public String say() {

             return "Hi";

       }

      

       public static void main(String[] args) {

             Test myTest = new Test();

             String a = myTest.say();

            

             System.out.print(a);

       }

}


리턴값받을변수 = 객체.메소드명()



입력 O 출력 X


public class Test {

       public void sum(int a, int b) {

             System.out.println(a+" "+b+" 합은"+(a+b)+"입니다"); //리턴값 아님

       }

      

       public static void main(String[] args) {

             Test myTest = new Test();

             myTest.sum(3, 4);

       }

}


객체.메소드명(입력인수1, 입력인수2, ...)


리턴값은 return으로만 돌려줘야 함.




입력 X 출력 X


public class Test {

       public void say() {

             System.out.println("Hi");

       }

      

       public static void main(String[] args) {

             Test myTest = new Test();

             myTest.say();

       }

}


객체.메소드명()




출처 : https://wikidocs.net/225

shift + F6 변수명 한번에 변경!

클래스명 바꿀 때도 사용 가능->관련 변수도 자동 변경됨!



match_parent 부모 뷰그룹에 크기 맞추기/버튼은 부모 뷰그룹 너비만큼

wrap_content 뷰 스스로 적당한 크기 맞추기/버튼의 경우 텍스트라벨의 너비만큼



+ Recent posts