'전체 글'에 해당되는 글 132건

반복문 for

Posted by PeEn
2019. 5. 26. 22:43 Programing/Python

for문 리스트

for 변수 in 리스트 :
    실행할 명령

*실행할 명령 전 들여쓰기 필수*

ex)

for num in [0,1,2]:
    print(num)
---------------

0|
1
2


for문 문자열

for 변수 in 문자열 :
    실행할 명령

ex)
for charname in '하나둘셋' :
    print(charname)
------------




ex)
nums = [0,1,2]
for num in nums:
    print(num)
    print(nums)
-------------------
0
[0,1,2]
1
[0,1,2]
2
[0,1,2]


for j in range(2,10):
    for i in range(1,10) :
        print('{} x {} = {}'.format(j, i, j*i)
----------
2 x 1 = 2
2 x 2 = 4
.........
9 x 9 = 81

 

 

'Programing > Python' 카테고리의 다른 글

while문  (0) 2019.05.27
if문  (0) 2019.05.26
논리형  (0) 2019.05.26
순서열  (0) 2019.05.26
Python LIST  (0) 2019.05.26

Python LIST

Posted by PeEn
2019. 5. 26. 19:30 Programing/Python

리스트 선언 및 추가

ListName.append

>>> color = ['레드','파랑','초록']
>>> color
['레드', '파랑', '초록']
>>> color.append("검정")
>>> color
['레드', '파랑', '초록', '검정']

 

리스트에서 아이템 제거

del ListName[index]

>>> color
['레드', '파랑', '초록', '검정']
>>> del color[2]
>>> color
['레드', '파랑', '검정']

 

리스트에서 일부 부분 가져오기

ListName[시작index : 끝index]

>>> color
['레드', '파랑', '검정', '노랑']
>>> color[2:3]
['검정']
>>> color[1:3]
['파랑', '검정']

리스트를 순서대로 정렬하기

ListName.sort()

>>> a = [1,3,2,7,4,23,9,5]
>>> a
[1, 3, 2, 7, 4, 23, 9, 5]
>>> a.sort()
>>> a
[1, 2, 3, 4, 5, 7, 9, 23]

 

리스트 내에 특정 값 개수 구하기

ListName.count(찾을값)

>>> color.append("검정")
>>> color
['레드', '파랑', '검정', '노랑', '검정']
>>> color.count('검정')
2
>>> color.count('파랑')
1

 

 

 

 

 

'Programing > Python' 카테고리의 다른 글

while문  (0) 2019.05.27
if문  (0) 2019.05.26
논리형  (0) 2019.05.26
순서열  (0) 2019.05.26
반복문 for  (0) 2019.05.26

S003_ListUsingArray RemoveData

Posted by PeEn
2019. 5. 14. 11:45 Programing/자료구조
#include <stdio.h>
#define LIST_LEN 3

int list[LIST_LEN];
int numOfData = 0;

void Insert(data){
	if(numOfData>=LIST_LEN){
		printf("저장이 불가합니다.\n");
		return;
		
	}
	list[numOfData++] = data; //++가 뒤에 붙으면 이 행이 실행 된 뒤 증가, 앞에 붙으면 먼저 증가하고 실 행 
	
}
void RemoveData(int data){
	int i;
	int n = numOfData;
	for(i=0;i<numOfData;i++){
		if(list[i]==data){
			n=i;
			break;
		}
	}
	for(i=n;i<numOfData;i++){
		list[i]=list[i+1];
		
	}
	if(n!=numOfData) //찾는 값이 없을 때는 n값이 numOfData 값과 동일 
	{ 
		numOfData--;
	}
	
}

	

void Printlist(){
	int i;
	printf("list Count(%d) : ",numOfData);

		for(i=0;i<numOfData;i++){
			printf("%d	",list[i]);
		}
	printf("\n\n");


}
void main(int argc, char* argv[]){
	Insert(15);Printlist();
	Insert(17);Printlist();
	Insert(19);Printlist();
	Insert(21);Printlist();
	RemoveData(1); Printlist();
	RemoveData(17); Printlist();

}
 

'Programing > 자료구조' 카테고리의 다른 글

Bubble Sort 연습  (0) 2019.06.17
S003_ListUsingArray  (0) 2019.05.14

S007_Sungjuk _허용할 범위_public, private, protect 개념

Posted by PeEn
2019. 5. 14. 11:44 Programing/Java
  • // public  = 누구나 사용할 수 있다.
  • // private = 혼자만 사용할 수 있다.
  • // protect =  상속자만 사용할 수 있다.
  • //   = 상관없다.
    1. public class Sungjuk (메인 매소드)
      package kr.ac.jj.java201562054;
      
      import java.util.Scanner;
      
      public class S007_Sungjuk { 
      
      	public static void main(String[] args) {
      		// TODO Auto-generated method stub
      		
      		HighStudent hs = new HighStudent();
      		
      		hs.Input();
      		hs.Print();
      		HighStudent hs2 = new HighStudent(100,99,100);
      		hs2.Print();
      		
      	}
      
      }
      
    2. public class HighStudent (매소드)
      package kr.ac.jj.java201562054;
      
      import java.util.Scanner;
      
      
      // public 	=	누구나 사용할 수 있다.
      // private	=	혼자만 사용할 수 있다.
      // protect	= 	상속자만 사용할 수 있다.
      //			=	상관없다.
      public class HighStudent {
      	private String name = "No Name";	//이름
      	private int kor;	//국어성적
      	private int eng;	//영어성적
      	private int mat;	//수학성적
      	private int tot;	//합계	
      	private double ave;	//평균
      	private String grade;	//등급
      	
      	public HighStudent(){
      		
      	
      	}
      	
      	public HighStudent(int kor, int eng, int mat){
      		this.kor = kor;
      		this.eng = eng;
      		this.mat = mat;
      		Calc();
      	}
      	
      	public void Input(){
      		Scanner scan = new Scanner(System.in);
      		System.out.print("이름:");
      		name = scan.next();
      		System.out.print("국어:");
      		kor = scan.nextInt();
      		System.out.print("영어:");
      		eng = scan.nextInt();
      		System.out.print("수학:");
      		mat = scan.nextInt();
      		Calc();
      	}
      	
      	public void Print(){
      		System.out.println(
      				name
      				+"\t"+kor
      				+"\t"+eng
      				+"\t"+mat
      				+"\t"+tot
      				+"\t"+String.format("%6.2f",ave)//소수점 자르기
      				+"\t"+grade
      				);
      	}
      	
      	private void Calc() {
      		tot = kor + eng + mat;
      		ave = (double)tot / 3;	
      		
      		if(ave >= 90) {
      			grade = "수";
      		}
      		else if(ave >= 80) {
      			grade = "우";
      		}
      		else if(ave >= 70) {
      			grade = "미";
      		}
      		else if(ave >= 60) {
      			grade = "양";
      		}
      		else {
      			grade = "가";
      		}
      		
      		
      	}
      	
      
      }
      
       

S003_ListUsingArray

Posted by PeEn
2019. 5. 14. 11:44 Programing/자료구조
#include
#define LIST_LEN 3 

int list[LIST_LEN]; 

int numOfData = 0;
void Insert(data){ 
	if(numOfData>=LIST_LEN){ 
    	printf("저장이 불가합니다.\n");
        return; 
    } 
    list[numOfData++] = data; //++가 뒤에 붙으면 이 행이 실행 된 뒤 증가, 앞에 붙으면 먼저 증가하고 실 행 
 }
 
 void Printlist(){
 	int i; 
	printf("list Count(%d) : ",numOfData); 
 
 	for(i=0;i<numOfData;i++){ 
 		printf("%d ",list[i]); 
    } 
 
	printf("\n\n"); 
 } 
 
 void main(int argc, char* argv[]){ 
 	Insert(15);Printlist(); 
    Insert(17);Printlist(); 
    Insert(19);Printlist(); 
    Insert(21);Printlist(); 
 }

'Programing > 자료구조' 카테고리의 다른 글

Bubble Sort 연습  (0) 2019.06.17
S003_ListUsingArray RemoveData  (0) 2019.05.14

S007_Sungjuk_UnivStudent 대학성적 계산예제

Posted by PeEn
2019. 5. 14. 11:32 Programing/Java
실행결과 소스코드
package kr.ac.jj.java201562054;

import java.util.Scanner;

public class S007_Sungjuk_UnivStudent {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		UnivStudent US = new UnivStudent();
		US.Input();
		US.Output();
	}

}

class UnivStudent {
	String stud_id; // 학번
	String name; // 이름
	String course; // 과목
	int pres; // 출석점수
	int rep; // 과제점수
	int midt; // 중간점수
	int finalt; // 기말점수
	double score; // 점수
	String grade; // 학점
	Scanner scan = new Scanner(System.in);

	void Input() {
		System.out.print("학번:");
		stud_id = scan.next();
		System.out.print("이름:");
		name = scan.next();
		System.out.print("과목:");
		course = scan.next();
		System.out.print("출석점수:");
		pres = scan.nextInt();
		System.out.print("과제점수:");
		rep = scan.nextInt();
		System.out.print("중간점수:");
		midt = scan.nextInt();
		System.out.print("기말점수:");
		finalt = scan.nextInt();
		Calcu();

	}

	void Output() {
		System.out.print(name + "학생의 총점은 " + score + "이고 학점은 " + grade + "입니다."

		);

	}

	void Calcu() {
		score = (pres + rep + midt + finalt) / 4.0;
		if (score >= 95) {
			grade = "A+";

		} else if (score <= 94 & score > 89) {
			grade = "A";
		} else if (score <= 89 & score > 84) {
			grade = "B+";
		} else if (score <= 84 & score > 79) {
			grade = "B";
		} else if (score <= 79 & score > 74) {
			grade = "C+";
		} else if (score <= 74 & score > 69) {
			grade = "C";
		} else if (score <= 69 & score > 64) {
			grade = "D+";
		} else if (score <= 64 & score > 59) {
			grade = "D";
		} else {
			grade = "F";
		}
	}

}
 

S007_Sungjuk 성적계산 및 입출력

Posted by PeEn
2019. 5. 14. 11:31 Programing/Java
package kr.ac.jj.java201562054;

import java.util.Scanner;

public class S007_Sungjuk {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		HighStudent hs = new HighStudent();
		
		hs.Input();
		
		hs.Print();
		
		HighStudent hs2 = new HighStudent(100,99,100);
		hs2.Print();
		
	}

}

class HighStudent{
	String name = "No Name";	//이름
	int kor;	//국어성적
	int eng;	//영어성적
	int mat;	//수학성적
	int tot;	//합계	
	double ave;	//평균
	String grade;	//등급
	
	HighStudent(){
		
	
	}
	
	HighStudent(int kor, int eng, int mat){
		this.kor = kor;
		this.eng = eng;
		this.mat = mat;
	}
	
	void Input(){
		Scanner scan = new Scanner(System.in);
		System.out.print("이름:");
		name = scan.next();
		System.out.print("국어:");
		kor = scan.nextInt();
		System.out.print("영어:");
		eng = scan.nextInt();
		System.out.print("수학:");
		mat = scan.nextInt();
		Calc();
	}
	
	
	void Print(){
		System.out.println(
				name
				+"\t"+kor
				+"\t"+eng
				+"\t"+mat
				+"\t"+tot
				+"\t"+String.format("%6.2f",ave)//소수점 자르기
				);
	}
	
	void Calc() {
		tot = kor + eng + mat;
		ave = (double)tot / 3;				
	}
}
	

 

S003_ContactsClass2 여러 Class 사용

Posted by PeEn
2019. 5. 14. 11:31 Programing/Java
package kr.ac.jj.java201562054;

import java.util.Scanner;

public class S003_ContactsClass2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Friend f = new Friend();

		f.Input();
		f.Print();

		Book b = new Book();
		b.BInput();
		b.BPrint();

	}

}

class Book {
	String title, author, publisher;// 제목 저자 출판사
	int price; // 가격
	Scanner scan = new Scanner(System.in);

	public void BInput() {
		System.out.printf("제목:");
		this.title = scan.next();

		System.out.printf("저자:");
		this.author = scan.next();

		System.out.printf("출판사:");
		this.publisher = scan.next();

		System.out.printf("가격:");
		this.price = scan.nextInt();

	}

	public void BPrint() {
		System.out.print("제목:" + this.title + "\n저자:" + author + "\n출판사:" + publisher + "\n가격:" + price);
	}

}

class Friend {
	String name;
	String phone;
	int speed_dial;

	public void Input() {
		Scanner scan = new Scanner(System.in);

		System.out.print("\n이름: ");
		this.name = scan.next();

		System.out.print("휴대폰: ");
		this.phone = scan.next();

		System.out.print("단축번호: ");
		this.speed_dial = scan.nextInt();
	}

	public void Print() {
		System.out.println("\n이름 : " + this.name + "\n휴대폰 : " + this.phone + "\n단축번호 : " + this.speed_dial);

	}
}
 

S003_ContactsClass1 클래스 사용

Posted by PeEn
2019. 5. 14. 11:29 Programing/Java
package kr.ac.jj.java201562054;

import java.util.Scanner;

public class S003_ContactsClass1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

					Person p = new Person();
					Person r = new Person();
					
				p.Input();
				r.Input();
				p.Print();
				r.Print();
		
}}

class Person {
	String name;
	String phone;
	int speed_dial;
	

	public void Input()
	{
		Scanner scan = new Scanner(System.in);
		
		System.out.print("이름: ");
		this.name = scan.next();
		
		System.out.print("휴대폰: ");
		this.phone = scan.next();
		
		System.out.print("단축번호: ");
		this.speed_dial = scan.nextInt();
	}
	
	public void Print()
	{
		System.out.println("이름 : "+this.name+
				"\n휴대폰 : "+this.phone+
				"\n단축번호 : "+this.speed_dial);

	}
	
}
 

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

S007_Sungjuk 성적계산 및 입출력  (0) 2019.05.14
S003_ContactsClass2 여러 Class 사용  (0) 2019.05.14
S003_Contacts  (0) 2019.05.14
T002_SmartPhoneContact 전화번호부 간단 입출력  (0) 2019.05.14
기본타입과 문자열  (0) 2019.05.14

S003_Contacts

Posted by PeEn
2019. 5. 14. 11:28 Programing/Java
package kr.ac.jj.java201562054;

import java.util.Scanner;

public class S003_Contacts {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
				
		System.out.print("이름: ");
		String name = scan.next();
		
		System.out.print("휴대폰: ");
		String phone = scan.next();
		
		System.out.print("단축번호: ");
		int speed_dial = scan.nextInt();
		
		System.out.println("이름 : "+name+
							"\n휴대폰 : "+phone+
							"\n단축번호 : "+speed_dial);
				
		
	}

}