Prime Number Determination [final check!]
   Hi, I had to make a java coding that will determine if a number is a prime number or not. Here's the coding I did:

 
```
    import.java.util.Scanner;
     public class PrimeNumber
    {
    public static void main(String args[]) 
     {
    int n;
    Scanner Prime = new Scanner(System.in);
    System.out.println(" Please enter a number: ");
    n = Prime.nextInt();
    System.out.println(isPrime(n));
    }
    static boolean isPrime(int n) {
    if (n%2==0) return false;
    for(int i=3;i*i<=n;i+=2) {
    if(n%i==0)
    return false;
    }
    return true;
    }
    } 

```
 And I got just 1 more error to correct here:

 
```
PrimeNumber.java:1: error: <identifier> expected
    import.java.util.Scanner;
          ^
1 error

```
 Can anyone please shed some light on correcting this 1 error in my java coding here? Thanks in advance!
Here, this should do it. I just replaced the

 
```
System.out.println(isPrime(n));

```
 part, which would print true or false, with an if

 
```
if (isPrime(n))
    System.out.println("The number is prime.\n");
else 
    System.out.println("The number is not prime.\n");

```
 Here's the code:

 
```
import java.util.Scanner;
public class PrimeNumber{
    public static void main(String args[]){
        int n;
        Scanner Prime = new Scanner(System.in);
        System.out.println(" Please enter a number: ");
        n = Prime.nextInt();
        if (isPrime(n))
            System.out.println("The number is prime.\n");
        else 
            System.out.println("The number is not prime.\n");
    }

    static boolean isPrime(int n) {
        if (n%2==0)return false;
        for(int i=3;i*i<=n;i+=2) {
            if(n%i==0)
                return false;
        }
        return true;
    }
} 

```
 This is a trivial task. You should probably read your coursebook/tutorials, I bet you'll find the answers there.
`stream`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

of `PriorityBlockingQueue`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

follows the order `Iterator`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

, which according to the [documentation](https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=) :



>  The iterator provided in the iterator () method is not guaranteed to traverse the PriorityBlockingQueue elements in any particular order.
> 
> 
> 


If you want order of precedence, you need `poll`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

items from `PriorityBlockingQueue`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

.



  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  


```
PriorityBlockingQueue<Integer> pq = new PriorityBlockingQueue<>();
pq.add(5);
pq.add(8);
pq.add(3);

System.out.println("-- Try 1 --");
pq.stream().forEach(System.out::println);

System.out.println("-- Try 2 --");
IntStream.range(0, pq.size()).map(i -> pq.poll()).forEach(System.out::println);

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

Conclusion (this may depend on Java implementation):



```
-- Try 1 --
3
8
5
-- Try 2 --
3
5
8

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
``` you can use the repmat function here
if you have to print the patter n (here 10) times, use the following code:
a = [5 4 3 2 1 0]';
n = 10;
b =repmat(a, n,1) > [[cite senthil kumar.p]]
>
> yes this is android studio project.
> 
> both input 1 and input 2 are integers.
> example:
> input1 = 1000
> input2 = 20
> 
> it will create total 50 rows and the order is 
> 0
> 20
> 40
> 60
> etc.....
> 
> 

do you need the codes as below? 
......
for (int i = input1 / input2; i >=0; i--) {
 ......
 t1v.settext("" + i * input2);
 ...... && is a short circuit operator in java, which means that once it evaluates the left expression as false - it no longer evaluates the right expression.   

in our case, in the equals method evaluates 

```

obj instanceof person 
```
 to **true**; 

```

this.age == ((person)obj).age 
```
 to **false**; the next expression, 
```

this.name.equals(((person)obj).name);
```
 is not evaluated at all, and the method returns **false**.   

changing the && operator to || or & would result in a java.lang.nullpointerexception Solution:


Hello Gavin,

You have got a nice question. No matter how the question is, don’t forget to ask. Thanks.  
There are a couple of ways to find the number in digits in a number. As you told you just started learning and well-known with the for-loop. I am trying to solve the problem using a simple iteration. Please have a look below program. I hope the program will clarify itself to you as you’ve covered the for-loop topic already.


```
public class DigitsInNumber{
    static int countDigit(long x){ 
        int counter = 0; 
        while (x != 0) { 
            x = x / 10; 
            ++counter; 
        } 
        return counter; 
    }

  	public static void main(String[] args){ 
        long x = 1052809467; 
        System.out.print("Number of digits : " + countDigit(x)); 
    } 
}
```
Thanks again. Good Day! use

summation of series of natural numbers -


 

- wherein

sum of first n natural numbers



 

 and

 

summation of series of natural numbers -


 

- wherein

sum of  squares of first n natural numbers



 

 

3+7+14+24+37 15k

let tn=an2+bn+c            because difference is in a.p: [4,7,10,13]

at n=1     (i)

    n=2      (ii)

    n=3        (iii)

    (ii)-(i)        (iv)

    (iii)-(ii)       (v)

    (v)-(iv)      

                    

 

from (i) 

from (ii) 







 



      

 

put n=15   

               

               

               

               

 




option 1)

126

this option is incorrect

option 2)

122

this option is correct

option 3)

81

this option is incorrect

option 4)

119

this option is incorrect (a) for digit



expression : 5n + 1

where n = no of digits

for 5 digits

no of segments required = 5(5) + 1 = 25 + 1 = 26

for 10 digits

no of segments required = 5(10) + 1 = 50 + 1 = 51

for 100 digits

no of segments required = 5(100) + 1 = 500 + 1 = 501

(b) for digit



expression : 3n + 1

where n = no of digits

for 5 digits

no of segments required = 3(5) + 1 = 15 + 1 = 16

for 10 digits

no of segments required = 3(10) + 1 = 30 + 1 = 31

for 100 digits

no of segments required = 3(100) + 1 = 300 + 1 = 301

(c) for digit



expression : 5n + 2

where n = no of digits

for 5 digits

no of segments required = 5(5) + 2 = 25 + 2 = 27

for 10 digits

no of segments required = 5(10) + 2 = 50 + 2 = 52

for 100 digits

no of segments required = 5(100) + 2 = 500 + 2 = 502 c = input()  

t = len(c)  

temp = ""  

for i in range(0,len(c)):  

    if t<3:  

        break  

    else:  

        if i in (0,1,t-2,t-1):  

            temp = temp+c[i]  

        else:  

            continue  

print(temp) the compiler will throw the following errors:  


10: error: increment of read-only variable **k**,  


12: error: **lvalue** required as increment operand. the code you posted above still has the original img tag with joy.jpg, so it doesn't show what you entered that did not work.
but taking a wild guess, i would point out that javascript is case-sensitive, and so is the challenge checker, so if you accidentally substituted lower case for upper case, or vice-versa, it would not work in the code or pass the challenge.