DS/Alogo Job Ready

 1)Check prime Is A Number Prime

concept:- no divide hona chiya khud sa ya fir apena app sa toa n  ko n number tak divde karka dekho then agar count 2 aya means 1 or apena app sa toa number is prime easy haa

1)for loop ;

2)int count = 0;

3)if check div horaha haa ke nahi t%i == 0;

4)if count==2 then prime;








public class HelloWorld{

     public static void main(String []args){
        System.out.println("Hello World");
        
        int t  = 114;
        int count = 0;
        
        for(int i = 1;i<=t;i++){
            if(t%i==0){
                count++;
            };
        };
            
            if(count==2){
                System.out.println("it is prime");
            }else{
                System.out.println("it is not prime");
            }
        
     }
}













import java.util.*;
  
  public class Main{
  
  public static void main(String[] args) {
      Scanner scn = new Scanner(System.in);
  
      int t = scn.nextInt();
      
      for(int i = 1;i<=t;i++){
          int n = scn.nextInt();
          int tf = 0;
          for(int j = 1;j<=n;j++){
              if(n%j==0){
                  tf++;
              }
          }
          if(tf ==2){
              System.out.println("prime");
          }
          else{
              System.out.println("not prime");
          }
      }
  
   }
  }

Comments

Popular posts from this blog

Git and Github

bubble short Q1

Java Program to Check Whether the String Consists of Special Characters