InterviewSolution
| 1. |
Q. 4 Solve Below entries with Group & Voucher Type:-a) Mr. Ram start business with Cash 20,00,000=00, Goods 10,00,000=00, Furniture 50,000-00. Computer 25.000-00Total rupees 3075000 |
|
Answer» blem statement is quite clear. First take the user input of a starting point (which we will do with java.util.Scanner) and then print the NEXT 50 primes.import java.util.Scanner;PUBLIC class FiftyPrimes{ // Return true if a number n is prime public static boolean isPrime(long n) { // Check division from 2 to sqrt(n) for (long i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) { return false; } } // If no division is found, number is prime return true; } public static void main(String[] args) { // Create Scanner object Scanner sc = new Scanner(System.in); // Take user input System.out.print("ENTER the starting point: "); long start = sc.nextInt(); // CLOSE Scanner object sc.close(); // If start point is LESS than 2, make it 2 if (start < 2) { start = 2; } int numberOfPrimes = 0; // Number of primes printed long number = start; // Number to be tested for prime // Iterate until 50 primes are printed while (numberOfPrimes < 50) { if (isPrime(number)) { System.out.println(number); numberOfPrimes++; } number++; } }} |
|