본문 바로가기

코드업기초4

코드업 기초100제, #1063 ~ #1072 🌼1063 📝 삼항 연산자 조건식 ? 피연산자1 : 피연산자2 조건식의 연산결과가 true 이면, 결과는 피연산자 1이고, 조건식의 연산결과가 false 이면 결과는 피연산자2 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); System.out.println( a > b? a : b); } } 🌼1064 📝 세 정수 중에 가장 작은 수 출력 import java.util.Scanner; public class Main { public static void .. 2022. 9. 12.
코드업 기초100제, #1053 ~ #1062 🌼1053 📝 NOT import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); System.out.println(a == 1? 0 : 1); } } 🌼1054 📝 AND import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); if(a == 1 && b ==1 ) .. 2022. 9. 11.
코드업 기초100제, #1043 ~ #1052 🌼1043 📝 나머지 출력 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); System.out.println(a % b); } } 🌼1044 📝 int 범위 -2,147,483,648 ~ 2,147,483,647 따라서 int보다 리터럴 범위가 큰 long으로 받아서 출력해줘야 한다. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc.. 2022. 9. 11.
코드업 기초100제 #1023 ~ #1032 🌼1023 //import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); String[] strSplit = str.split("\\."); //System.out.println(Arrays.toString(strSplit)); System.out.println(strSplit[0] + '\n' + strSplit[1]); } } 🌼1024 📝 string.length() 문자열의 길이. 즉, 문자의 갯수를 의미한다. 📝 While문 for (i = .. 2022. 9. 7.