import java.util.Scanner; public class NthPrime { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter n to compute the nth prime number: "); int nth = sc.nextInt(); int num, count, i; num=1; count=0; while (count < nth){ num=num+1; for (i = 2; i <= num; i++){ if (num % i == 0) { break; } } if ( i == num){ count = count+1; } } System.out.println("Value of nth prime: " + num); } }
Rohit wants to add the last digits of two given numbers. For example, If the given numbers are 267 and 154, the output should be 11.
Below is the explanation - Last digit of the 267 is 7 Last digit of the 154 is 4 Sum of 7 and 4 = 11
Note: The sign of the input numbers should be ignored. i.e. if the input numbers are 267 and 154, the sum of last two digits should be 11 if the input numbers are 267 and -154, the sum of last two digits should be 11 if the input numbers are -267 and 154, the sum of last two digits should be 11 if the input numbers are -267 and -154, the sum of last two digits should be 11
Example : Let the list be {2,3,5} and Assume always 1 be included then
2th number is 2 3th number is 3 4th number is 4 5th number is 5 6th number is 6 7th number is 8 8th number is 9 9th number is 10 10th number is 12 11th number is 15 and so on...
Input array: [-2,1,3,5,6,7,8,10,12,15,17,19,20] Sum : 20
Output
6, 12 3, 15 1, 17 -2, 20 8, 10
Required best time complexity and effective code