본문 바로가기
728x90
반응형

Array6

[JavaScript] array 배열 배열선언 const array = [273, 'String', true, function () { }, {}, [273, 103]] 이런식으로 [] 안에 선언 push push하면 맨 뒷부분에 추가 된다. 배열.push(요소) 인덱스를 지정해서 삽입하기 비어있는 값은 empty로 출력된다. splice 배열.splice(인덱스, 제거할 요소의 개수) indexOf 요소의 위치값 확인 const itemsB = ['사과', '배', '바나나'] const index = itemsB.indexOf('바나나') index itemsB.splice(index, 1) itemsB itemsB.indexOf('바나나') 바나나는 배열에 없으므로 -1을 출력한다. ◦배열의 특정 위치에 요소 추가 배열.splice(인.. 2022. 12. 20.
[REACT/JavaScript] map() map() JavaScript의 표준 내장 객체 Array의 메소드 prototype.map()이다. 배열 내의 모든 요소 각각에 대하여 주어진 함수를 호출한 결과를 모아 새로운 배열을 반환한다. 형식 arr.map(callback(currentValue[, index[, array]])[, thisArg]) Ex01. import { useState } from "react"; const IterationSample = () => { const names = ['눈사람', '호빵', '눈', '바람']; const nameList = names.map( (currentValue, index, array) => currentValue={currentValue} index={index} array={arr.. 2022. 12. 8.
[Java] 2차원 배열의 생성 및 합과 평균 구하기 public class ArrayCopy04 { public static void main(String[] args) { int arr[][] = {{80,20}, {40,50,10},{100,100,100,100,100}}; int sum=0; int num=0; double avg=0.0; for(int i=0; i 2022. 10. 6.
[JAVA] Array의 활용 최대값과 최소값 구하기 public class ArrayTest2 { public static void main(String[] args) { int score[] = {55, 45, 34, 3, 4, 23, 45, 34, 56}; //최대값 구하기 int max = score[0]; for(int i=1; i max) max = score[i]; } System.out.println("최대 값은 : " + max); //최소값 구하기 int min = score[0]; for(int i=1; i 2022. 10. 5.
[JAVA] Array 배열이란, 같은 형의 데이터를 하나의 자료구조에 저장할 수 있게 만든 것이다. 같은 형의 데이터를 여러 개 사용할 때 많은 변수를 사용하기 보다는 배열을 사용하는 것이 효율적이다. 배열은 기본 자료형이 아니라 참조 자료형이다 배열 각각의 요소는 기본 자료형, 참조 자료형 모두 가능하다 배열의 초기화 배열의 초기화란, 처음 생성된 배열에 데이터를 저장하는 과정이다. 변수와 달리 배열은 초기화 하지 않아도 사용이 가능하다 (오류 발생 안함) 배열이 초기화 되지 않을 경우에는 묵시적인 값으로 자동 설정된다. public static void main(String[] args) { int id[] = new int[5]; System.out.println(id[0]); System.out.println(id[1.. 2022. 10. 5.
[JAVA] 동전 계수기 프로그램 돈의 액수를 입력 받아 오만원권, 만원권, 천원권, 500원짜리 동전, 100원 짜리 동전, 1원 짜리 동전이 각각 몇개인지 출력하는 동전게수기 프로그램을 작성하시오 01. 계산식 이용 import java.util.Scanner; public class Ex05 { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); System.out.print("돈의 액수를 입력하세요 >> "); int money = stdin.nextInt(); int won50000 = money/50000; int moneyCir = money%50000; int won10000 = moneyCir/10000; moneyCir = mo.. 2022. 9. 16.
728x90
반응형