JAVA/JAVA 연습 9

DO IT 연습 문제 1

1.네값의 최댓 값을 구하는 메서드 작성 import java.util.Scanner; public class Max4Method { static int max4(int a,int b,int c, int d) { int max = a; if (max < b) { max = b; } if (max < c) { max = c; } if (max < d) { max = d; } return max; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("세개의 정수를 입력하세요"); System.out.print("a의 값 :"); int a = sc.nextInt(); System.ou..

JAVA/JAVA 연습 2022.10.31

Do it! 자바 프로그래밍 : 연산자 01

산술 연산자로 총점과 평균 구하기 74p public class OperationEx1 { public static void main(String[] args) { int mathScore = 90; int engScore = 70; int totalScore = mathScore+engScore; System.out.println(totalScore); double avgscore = totalScore/2; System.out.println(avgscore); } } 증가, 감소 연산자로 값 연산하기 75p public class OperationEx2 { public static void main(String[] args) { int gameScore = 150; int lastScore1 = ++..

JAVA/JAVA 연습 2022.10.01

JAVA 토끼와 거북이 (최대 공약수 ,최소공배수)

토끼는 N분에 한 번 휴식을 하고 거북이는 M분에 한 번 휴식을 함 토끼와 거북이가 처음으로 같이 쉬는 시간은 언제? 입력 3 5 출력 15 code import java.util.*; public class Main { public static void main(String args[]) { int rabbit, turtle; Scanner scan = new Scanner(System.in); rabbit = scan.nextInt(); turtle = scan.nextInt(); int a,b,r; a = rabbit; b = turtle; r = 1; boolean c = true; //최대 공약수 while(c){ if(b%a !=0){ r=b%a; b=a; a=r; c=true; } else{..

JAVA/JAVA 연습 2022.09.30

JAVA 개굴개굴 개구리

엘리스와 개구리 대화 입력 안녕 나는 엘리스야 출력 개굴개굴 개굴개굴 개굴개굴개굴개굴 풀이 import java.util.*; public class Main { public static void main(String args[]) { Scanner scan = new Scanner(System.in); String str = scan.nextLine(); String output =""; String gegul = "개굴"; int len = str.length(); for(int i = 0; i < len; i++){ if(str.charAt(i) !=' '){ output = output + gegul; } else{ output = output + " "; } } //System.out.print..

JAVA/JAVA 연습 2022.09.25

Do it! 자바 프로그래밍 : 변수와 자료형 02

7.논리형 연습 public class BooleanEx { public static void main(String[] args) { boolean isMarred = true; System.out.println(isMarred); } } 8.자료형 추론 public class TypeInference { public static void main(String[] args) { int i = 10; var j = 10.0; var str = "hello"; System.out.println(i); System.out.println(j); System.out.println(str); } } 9.상수 사용 public class Constant { public static void main(String[] ..

JAVA/JAVA 연습 2022.09.25

Do it! 자바 프로그래밍 : 변수와 자료형 01

1.변수 선언과 사용 public class Variable1 { public static void main(String[] args) { int level; //선언 level = 10; //변수에 10을 대입 System.out.println(level); } } 2.변수 초기화 public class Variable2 { public static void main(String[] args) { int level = 10; //level 변수 선언과 동시에 값을 대입 System.out.println(level); } } 3.문자형 연습 public class CharacterEx1 { public static void main(String[] args) { char ch1 = 'A'; System...

JAVA/JAVA 연습 2022.09.25