전체 글(254)
-
1211JAVA -Test03
package dec11; public class Test03 { public static void main(String[] args) { int i = 0; int sum = 0; while (i
2023.12.11 -
1211JAVA -Test02
package dec11; public class Test02 { public static void main(String[] args) { int[] a = new int[8]; int i = 0; int n = 10; while (n >= 1) { a[i++] = n % 2; n /= 2; } for (i = 7; i >= 0; i--) { //출력하기 위해 >>맨끝자리부터 출력을 해라 System.out.print(a[i]);// 00001010 } } } 00001010
2023.12.11 -
1211JAVA -Test01
package dec11; public class Test01 { public static void main(String[] args) { //진법문제 //10->1010 //System.out.println(Integer.toBinaryString(10)); int number = 6;// //number / 2= 0; 몫 //number % 2 =0; 나머지 while (number >= 1 /*조심하세요*/) {//'while' 반복문을 사용해서 괄호 안의 조건이 참인 동안 계속 반복합니다. //반복문 안에서는 두 가지를 하려고 해요: System.out.println(number % 2); //1. 'number'를 2로 나눴을 때 나머지를 출력합니다. //2로 나눴을때 나머지 값 출력하기 //n..
2023.12.11 -
1211JAVA -While05
package dec11; import java.util.Scanner; public class While05 { public static void main(String[] args) { //스캐너 객체 만들기 Scanner sc = new Scanner(System.in); int input; System.out.println("1가위\t2.바위\t3.보");//\t탭 input = sc.nextInt(); while(input 3 ) { System.out.println("다시 입력"); //다시 입력받기 input = sc.nextInt(); } System.out.println("통과"); sc.close(); } } 1가위 2.바위 3.보 4 다시 입력 3 통과
2023.12.11 -
1211JAVA -While04
package dec11; import java.util.Scanner; //점수는 0~100까지의 숫자입니다. //사용자가 입력하는 숫자가 점수 범위에 들어가는지 Scanner sc = new Scanner(System.in); //while문으로 검사하는 프로그램 만들어주세요. //프로그램 시작->점수를 입력하세요(0~100) //120을 입력할 경우 -> 올바른 숫자가 아닙니다. 다시 입력해주세요. //100을 입력할 경우->프로그램 종료 //한글 public class while04 { public static void main(String[] args) { //스캐너 만들기 Scanner sc = new Scanner(System.in); //저장 변수 만들기 int score; System.o..
2023.12.11 -
1208JAVA -While01
package des08; import java.io.IOException; //반복문 중 무한 반복이 가능한 while입니다. /* * while문은 보통 무한 반복을 하다가 특정 조건이 되면 탈출합니다. * 채팅이나 게임 등 무한 반복되는 로직에서 사용됩니다. * 무한loop * * */ public class While01 { public static void main(String[] args) throws IOException { // while (1 + 1 == 2) { // // 조건이 참일때 실행 // System.out.println("2맞음"); // } boolean quit = true; while (quit) { System.out.println("게임을 시작합니다."); Syste..
2023.12.08