outer_loop: while (true) { while (true) { grade = scan.nextInt(); if (grade < 0) { break outer_loop; } } ... } //move이 경우 //move 위치로 이동.
package hanjagonghomework; public class Homework0707 { public static void main (String []ar) throws java.io.IOException{ int count = 0; for(int num=3; num<=100; num++){ int t; two : for(t=2; t<num; t++){ if(num%t==0){ break two; } else{ continue two; } } if(num-t<=1){ System.out.println(num + " "); count+=1; } } System.out.println("소수는 총" + count + "개 입니다."); } }
public class PrimeNumber{ public static void main(String []args){ int numOfPrime = 0, i, j; for(i = 2; i <= 100; i++) { for(j = 2; j < i; j++) { if(i % j == 0) break; } if(j == i) { numOfPrime++; System.out.print(i + " "); } } System.out.println("\n소수의 개수는 " + numOfPrime); } }
public class Jisu { public static void main(String[] ar){ int num = 2, i; System.out.println("\nprime numbers between 1 and 100 are : "); while(num <= 100){ for(i=2; i<=num; i++){ if(num%i == 0 && i != num){ num++;break; } if(i >= num-1){ System.out.print(num + " "); num++;break; } } } System.out.println(); } }
package assignment; public class _20140707{ public static void main(String[] args){ boolean bool; for(int k=2;k<=100;k++){ bool = true; for(int i=k-1;i!=1;i--){ if(k % i == 0){ bool = false; break; } } if(bool == true) System.out.println(k); } } } // 다이나믹 코딩을 이용 public static void main(String[] args){ int []prime = new int [100]; int j=0; boolean bool; for(int k=2;k<=100;k++){ bool = true; for(int i=0;prime[i]>0;i++){ if(k % prime[i] == 0){ bool = false; break; } } if(bool == true){ prime[j] = k; System.out.println(k); j++; } } }
package study; import java.lang.*; public class study1 { public static void main(String[] args) { boolean temp; for(int num = 2;num<=100;num++) { temp = true; for(int div_num = 2;div_num<num;div_num++) { if(num % div_num == 0) temp = false; } if(temp == true) System.out.printf("%d ",num); } } }