Notice
Recent Posts
Recent Comments
Link
기린의 기록을 위한 공간
[JAVA]codeUp코드업 기초100제 자바로 풀기(1022~1040) 본문
1022
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String data = sc.nextLine();
System.out.println(data);
}
}
1023
package com.algo.controller;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String num = sc.nextLine();
StringTokenizer st = new StringTokenizer(num,".");
String [] nums = new String[2];
int i = 0;
while(st.hasMoreTokens()) {
nums[i] = st.nextToken();
i+=1;
}
System.out.println(nums[0]+"\n"+nums[1]);
}
}
1024
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
//원하는 숫자를 문자열로 입력받는다 54321
String num = sc.nextLine();
//문자열을 문자배열로 변경
char [] nums = num.toCharArray();
//첫번째 for문 행
//5를 찍고 밑에 for문으로 내려간다
for(int i=0; i<nums.length; i++) {
System.out.print(nums[i]);
//두번째 for문 열
//4부터 0까지 -- "0"4개찍음 / 3부터 1까지 -- "0"3개찍음
for(int n=nums.length-1; n>i; n--) {
System.out.print("0");
}
System.out.println();
}
}
}
1025
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String text = sc.nextLine();
char total[] = text.toCharArray();
for(int i=0; i<total.length; i++) {
System.out.println("'"+total[i]+"'");
}
}
}
1026
package com.algo.controller;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String time = sc.nextLine();
StringTokenizer st = new StringTokenizer(time,":");
String [] times = new String[4];
int i=0;
while(st.hasMoreTokens()) {
times[i] = st.nextToken();
i+=1;
}
System.out.print(times[1]);
}
}
1027
import java.util.Scanner;
import java.util.StringTokenizer;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String time = sc.nextLine();
StringTokenizer st = new StringTokenizer(time,".");
String [] times = new String[4];
int i=0;
while(st.hasMoreTokens()) {
times[i] = st.nextToken();
i+=1;
}
System.out.print(times[2]+"-"+times[1]+"-"+times[0]);
}
}
1028
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
long num = sc.nextLong();
if(num>=0&&num<4294967295L) {
System.out.println(num);
}else {
System.out.println("범위가 아닙니다.");
}
}
}
1029
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
double num = sc.nextDouble();
System.out.printf("%.11f",num);
}
}
1030
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
long num = sc.nextLong();
System.out.print(num);
}
}
1031
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
//10진수->8진수 변환 메소드
//toOctalString()
String octalNum = Integer.toOctalString(num);
System.out.print(octalNum);
}
}
1032
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
//10진수->16진수 변환 메소드
//toHexString()
String hexnum = Integer.toHexString(num);
System.out.print(hexnum);
}
}
1033
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
//10진수->16진수 대문자
//String.format() 메소드에서 %X는 대문자, %x는 소문자
String hexnum = String.format("%X", num);
System.out.print(hexnum);
}
}
1034
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String octalNum = sc.nextLine();
//8진수->10진수
//Integer.parseInt(문자열, 원하는 진수)
//문자열을 원하는 진수에 맞춰 형변환한 것을 int변수에 넣는다
int num = Integer.parseInt(octalNum, 8);
System.out.print(num);
}
}
1035
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String hexNum = sc.nextLine();
//문자열 hexNum을 16진수로 바꾼다
int num = Integer.parseInt(hexNum, 16);
//int num을 8진수로 바꾼다
String octNum = Integer.toOctalString(num);
System.out.print(octNum);
}
}
1036
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
char word = sc.next().charAt(0);
System.out.println((int)word);
}
}
1037
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.println((char)num);
}
}
1038
package com.algo.controller;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String nums = sc.nextLine();
StringTokenizer st = new StringTokenizer(nums, " ");
String [] arr = new String[2];
int i=0;
while(st.hasMoreTokens()) {
arr[i] = st.nextToken();
i+=1;
}
//String배열에 담긴 문자열을 int로 형변환
int a = Integer.parseInt(arr[0]);
int b = Integer.parseInt(arr[1]);
System.out.print(a+b);
}
}
1039
package com.algo.controller;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String nums = sc.nextLine();
StringTokenizer st = new StringTokenizer(nums, " ");
String [] arr = new String[2];
int i=0;
while(st.hasMoreTokens()) {
arr[i] = st.nextToken();
i+=1;
}
//String배열에 담긴 문자열을 long으로 형변환
long a = Long.parseLong(arr[0]);
long b = Long.parseLong(arr[1]);
System.out.print(a+b);
}
}
1040
package com.algo.controller;
import java.util.Scanner;
public class Code{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
//num이 0보다 크면 -를 붙인다
if(num>0) {
System.out.print(-num);
//num이 0보다 작으면 -(-num) == num
}else if(num<0) {
System.out.println(-num);
//둘다아니면 num
}else {
System.out.println(num);
}
}
}
'Algorithm > codeUp기초100제' 카테고리의 다른 글
[JAVA]codeUp코드업 기초100제 자바로 풀기(1081~1099) (5) | 2020.03.01 |
---|---|
[JAVA]codeUp코드업 기초100제 자바로 풀기(1061~1080) (0) | 2020.02.27 |
[JAVA]codeUp코드업 기초100제 자바로 풀기(1041~1060) (0) | 2020.02.23 |
[JAVA]codeUp코드업 기초100제 자바로 풀기(1015~1021) (0) | 2020.02.21 |
[JAVA]codeUp코드업 기초100제 자바로 풀기(1001~1014) (0) | 2020.02.21 |
Comments