Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static int is_it_prime(int x){
- for(int i = 1; i <= x/2; i++){
- if(x%2 == 0){
- return 0;
- }
- }
- return 1;
- }
- public static void main(String[] args) {
- if(is_it_prime(31) == 1){
- System.out.println("yes");
- }else{
- System.out.println("no");
- }
- }
- }
- package com.company;
- import java.util.Arrays;
- import java.util.List;
- public class Main {
- public static int search_number(Integer x, List<Integer> list){
- for(int i = 0; i < list.size(); i++){
- if(list.get(i) == x){
- return 1;
- }
- }
- return 0;
- }
- public static void main(String[] args) {
- List<Integer> list = Arrays.asList(1, 3, 12, 99, 204, 909876);
- if(search_number(7, list) == 1){
- System.out.println("Found the number");
- }
- else{
- System.out.println("Not Found");
- }
- }
- }
- package com.company;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- public class Main {
- public static List<Integer> common_divisor(Integer x, Integer y){
- Integer max = Math.max(x, y);
- Integer min = Math.min(x, y);
- var list = new ArrayList<Integer>();
- for(int i = 1; i <= min; i++){
- if((max%i == 0 && min%i == 0) == true){
- list.add(i);
- }
- }
- return list;
- }
- public static void main(String[] args) {
- System.out.println(common_divisor(12, 24));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement