본문 바로가기
Coding Test/CodeUp

CodeUp_Java 기초 100제 - [기초-반복실행구조] 0 입력될 때까지 무한 출력하기(1)~(3) 71~73

by SeleniumBindingProtein 2022. 2. 14.
728x90
반응형

//자바코드
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);
        //입력 받은 정수를 저장할 num 선언
        int num;
        //while문의 제어 변수 check를 true로 선언 
        boolean check = true;
        
        while(check){
        	//입력된 정수를 num에 저장
        	num = sc.nextInt();
            
            if(num==0){
            	check = false;
            } else{
            	System.out.println(num);
            }
        }
        sc.close();
    }
}

 

//자바코드
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int num;
        
        for(int i=0;i<count;i++){
        	//count 개의 정수를 입력
        	num = sc.nextInt();
            System.out.println(num);
        }
        sc.close();
    }
}

//자바코드
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);
        //입력 받은 정수를 저장할 num 선언
        int num;
        //while문의 제어 변수 check를 true로 선언 
        boolean check = true;
        
        while(check){
        	//입력된 정수를 num에 저장
        	num = sc.nextInt();
            
            if(num==0){
            	check = false;
            } else{
            	System.out.println(num);
            }
        }
        sc.close();
    }
}
728x90
반응형

댓글