Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 15 additions & 72 deletions week1/day1/assignments/PrimeNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,24 @@


public class PrimeNumber {



/*

* Goal: To find whether a number is a Prime number or not

*

* input: 13

* output: 13 is a Prime Number

*

* Shortcuts:

* 1) Print : type: syso, followed by: ctrl + space + enter

* 2) To create a 'for' loop: type 'for', followed by ctrl + space + down arrow + enter

* 3) To create an 'if' condition: type 'if', followed by ctrl + space +down arrow + enter

*

* What are my learnings from this code?

* 1)

* 2)

* 3)

*

*/



public static void main(String[] args) {



// Declare an int Input and assign a value 13



// Declare a boolean variable flag as false



// Iterate from 2 to half of the input



// Divide the input with each for loop variable and check the remainder

Prime(7);
}

public static void Prime(int n ) {
boolean res= true;
for (int i=2;i<n/2;i++) {
if(n%i==0) {
res=false;
System.out.println("number is not Prime");
break;
}


// Set the flag as true when there is no remainder


// break the iterator


// Check the flag (Provide a condition)

}
if(res==true)
System.out.println("Prime Number");


// Print 'Prime' when the condition matches



// Print 'Not a Prime' when the condition doesn't match

}
}

}