[JAVA] Try to display prime numbers using boolean type

Since we learned boolean type, check the code that outputs prime numbers from 2 to 100.

 public class Qiita {
public static void main(String[] args) {
	boolean bl=true;

	for(int i=2; i<=100; i++) {
		for(int j=2; j<=(i/2); j++) {
			if(i%j==0){
				bl=false;
			}
		}
		if(bl==true){
			System.out.println(i);
		}else{
			bl=true;
		}
	}
} 
}

//実行結果 2,3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,71, 73, 79, 83, 89, 97,

I got the expected result.

Recommended Posts

Try to display prime numbers using boolean type
(Android) Try to display static text using DataBinding
[Java] Try to implement using generics
How to find Java prime numbers
Try to display a slightly rich Webview in Swift UI using UIViewRepresentable
Try to sort classes by enumeration type
Try to make a music player using Basic Player
Try to display hello world with spring + gradle
Try using libGDX
Try using Maven
Try using powermock-mockito2-2.0.2
Try using GraalVM
Try using jmockit 1.48
Try using sql-migrate
Try using SwiftLint
Try using Log4j 2.0
Judge prime numbers
How to add characters to display when using link_to method
Try to implement using Rakuten product search API (easy)
Try adding SMS authentication (using Twilio) to Keycloak's authentication process
Try to build a Java development environment using Docker
Command to try using Docker for the time being
Try to work with Keycloak using Spring Security SAML (Spring 5)
Try to implement tagging function using rails and js