H. colleagues, tell me, please, how to print also the message that the number is composite. Thank!
int n=9; for (int i=2; i<n; i++) { if ((n%i)==0) { System.out.println (n+"-is not prime number "); } } H. colleagues, tell me, please, how to print also the message that the number is composite. Thank!
int n=9; for (int i=2; i<n; i++) { if ((n%i)==0) { System.out.println (n+"-is not prime number "); } } decided so
public class cycles3 { public static void main (String []args) { int n=9; int m=0; for (int i=2; i<n; i++) { if (n%i==0) { m++; } } if (m==0) { System.out.println (n+"-is the prime number "); } else { System.out.println (n+"-is not prime number "); } } } double toTest = 23.23d; int flooredValue = (int) toTest; double resultDouble = (double)toTest - flooredValue; if(resultDouble == 0) { System.out.println("целое"); } else { System.out.println("НЕ целое"); } To check the simplicity of the number, your code can be used as follows:
Create a boolean variable with a value of true , set false if the condition is met. After the cycle, check the total value.
import java.util.Scanner; class TrueFals{ public static boolean isDivisible(double n, double m){ double x = n / m; return ((x % 1) == 0); } public static void main(String[] args){ Scanner in = new Scanner(System.in); double n = in.nextInt(); double m = in.nextInt(); boolean tf = isDivisible(n, m); System.out.println(tf); } } Source: https://ru.stackoverflow.com/questions/536977/
All Articles
System.out.println("Число является целым");. Do not thank. - VladD 4:44 pm