JAVA (187) 썸네일형 리스트형 객체//Sorting public static void main(String[] args) { Sorting sort = new Sorting(); sort.input(); sort.sorting(); sort.result(); } --------------------------------------------------------------------------- public class Sorting { //변수선언 -> 멤버변수(두가지 이상 처리(메소드)에서 접근해야 하는 경우) int number[]; boolean updown; //처리 public void input() { Scanner sc = new Scanner(System.in); System.out.println("정렬 할 갯수 ="); int count .. Object Oriented Programming(객체지향 프로그래밍) 이론 절차지향 : 처리중심 -> 객체지향 : 설계중심 *class MyClass{ //class의 설계 변수(멤버변수) - 접근지정(외부, 내부) 함수(메소드) - 처리 } *클래스명 변수(instance) = new 클래스명(); MyClass cls = new MyClass(); //동적할당 없이 사용 불가 ->stack영역 -> heap영역 기존방식 //TV -> 2대 String name[] = new String[2];//삼성, LG int channel[] = new int[2];//채널 수 boolean power[] = new boolean[2];// on/off //String name[0] = "삼성";//거실 name[1] = "LG";//방 channel[0] = 11; channel[1.. 함수// 학생 성적 입출력 프로그램 1. static int getSearchIndex(String student[][], String name) { //2개이상 중복되는 코드는 함수로 빼주는 것이 좋음 int findIndex = -1; for (int i = 0; i < student.length; i++) { String n = student[i][0]; if(n.equals(name)) { findIndex = i; break; } } return findIndex; } 를 getSearchIndex로 함수로 빼주고 return 값을 줘서 빈 인덱스 자리를 찾아 입력하게 될 때마다 int findIndex = getSearchIndex(student, name); 로 호출하여 사용함 2. static void allPrint(Str.. 학생 성적관리 프로그램 (미완성) public static void main(String[] args) { /* 학생 성적 관리 String student[][]; 메뉴 --- 1. 학생 정보 추가insert(예: 홍길동, 나이, 영어, 수학) 2. 학생 정보 삭제delete 3. 학생 정보 검색search 4. 학생 정보 수정update 5. 학생 정보 모두 출력 6. 과목의 총점-> 1. 영어2.수학 7. 과목의 평균 8. 성적순으로 정렬 9. 데이터 저장 */ Scanner sc = new Scanner(System.in); String student[][] = new String [20][4]; int choice; for (int i = 0; i < student.length; i++) { for (int j = 0; j < s.. 파일//함수// 배열 파일 완성판 public static void main(String[] args) { /* write 함수 String arrAtr[] = { "Hello", "안녕하세요", "Hi" }; 파일명.txt 저장되는 함수 read 함수 String strArr[]; [0] pw 간단입력문제 PrintWriter를 통해 data.txt파일에 안녕하세요. PrintWriter입니다.라고 적어보세요 import java.io.*; public class CharIOExam{ public static void main(String[]args){ PrintWriter pw = null; String str = "안녕하세요. PrintWriter입니다."; try{ pw = new PrintWriter(new FileWriter("data.txt")); pw.println(str); }catch(Exception e){ e.printStackTrace(); }finally{ try{ pw.close(); }catch(Exception e){ e.printStackTrace(); } } System.o.. char 단위 입출력(나) ( Reader나 Writer로 끝나는 것들 ) * 파일에서 읽어들이기 위해서는 : 파일리더 * 한줄씩 읽어들이기 위해서는 : 버퍼드리더 기본 public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // 버퍼리더 안에- 입력을 받을부분은 키보드여서 System.in이 들어가야 하는데 바로 들어갈 수 없어서 위와같이 넣어줌 String line = null; try { line = br.readLine(); }catch(IOException e) { e.printStackTrace(); } System.out.println(line); } 파일 파일에서 입력.. 다양한 타입의 입/출력(나) 출력 - (새파일생성) 원하는 값을 내보낼 때 out.write변수형(값);을 사용 out.writeInt(100);//정수 out.writeBoolean(true);//불린-1byte out.writeDouble(50.5);//실수 public static void main(String[] args) throws Exception { try( DataOutputStream out = new DataOutputStream(new FileOutputStream("파일경로지정")); ){ out.writeInt(100);//정수 out.writeBoolean(true);//불린-1byte out.writeDouble(50.5);//실수 }catch(Exception e) { e.printStackTrace(.. 이전 1 ··· 6 7 8 9 10 11 12 ··· 24 다음