Tumgik
arpit143blog · 1 year
Text
generates and prints the first N prime numbers:
import java.util.Scanner; public class PrimeNumberGenerator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the number of prime numbers to generate: "); int numPrimes = scanner.nextInt(); scanner.close(); System.out.println("The first " + numPrimes + " prime numbers are:"); generateAndPrintPrimes(numPrimes); } public static boolean…
View On WordPress
0 notes
arpit143blog · 1 year
Text
Java program that reverses a string:
javaCopy codeimport java.util.Scanner; public class StringReversal { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a string: "); String input = scanner.nextLine(); scanner.close(); String reversed = reverseString(input); System.out.println("Reversed string: " + reversed); } public static String reverseString(String input)…
View On WordPress
0 notes
arpit143blog · 1 year
Text
Java program that finds the maximum element in an array:
javaCopy codepublic class ArrayMaxElement { public static void main(String[] args) { int[] numbers = {5, 8, 3, 9, 2}; int max = findMaxElement(numbers); System.out.println("Maximum element: " + max); } public static int findMaxElement(int[] numbers) { int max = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] > max) { max = numbers[i]; } } return max; } } In this…
View On WordPress
0 notes
arpit143blog · 1 year
Text
Java program that checks if a string is a palindrome or not:
javaCopy codeimport java.util.Scanner; public class PalindromeChecker { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a string: "); String input = scanner.nextLine(); scanner.close(); boolean isPalindrome = checkPalindrome(input); if (isPalindrome) { System.out.println("The string is a palindrome."); } else { System.out.println("The…
View On WordPress
0 notes
arpit143blog · 1 year
Text
Java program that performs bubble sort on an array of integers:
javaCopy codepublic class BubbleSort { public static void main(String[] args) { int[] numbers = {7, 2, 9, 1, 5}; System.out.println("Before sorting:"); printArray(numbers); bubbleSort(numbers); System.out.println("After sorting:"); printArray(numbers); } public static void bubbleSort(int[] numbers) { int n = numbers.length; boolean swapped; for (int i = 0; i < n - 1; i++) { swapped =…
View On WordPress
0 notes
arpit143blog · 1 year
Text
Java program that calculates the Fibonacci series up to a given number of terms:
javaCopy codeimport java.util.Scanner; public class FibonacciSeries { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the number of terms: "); int numTerms = scanner.nextInt(); scanner.close(); System.out.println("Fibonacci series up to " + numTerms + " terms:"); for (int i = 0; i < numTerms; i++) { int fibNumber =…
View On WordPress
0 notes
arpit143blog · 1 year
Text
Java program that calculates the factorial of a number using recursion:
javaCopy codeimport java.util.Scanner; public class Factorial { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int number = scanner.nextInt(); scanner.close(); int factorial = calculateFactorial(number); System.out.println("Factorial of " + number + " is: " + factorial); } public static int calculateFactorial(int number)…
View On WordPress
0 notes
arpit143blog · 1 year
Text
Java program that finds the sum of digits in a number:
javaCopy codeimport java.util.Scanner; public class SumOfDigits { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int number = scanner.nextInt(); scanner.close(); int sum = calculateSumOfDigits(number); System.out.println("Sum of digits in " + number + " is: " + sum); } public static int calculateSumOfDigits(int number)…
View On WordPress
0 notes
arpit143blog · 1 year
Text
Java program : that calculates the sum of numbers in an array
javaCopy codepublic class ArraySum { public static void main(String[] args) { int[] numbers = {2, 4, 6, 8, 10}; int sum = calculateSum(numbers); System.out.println("Sum of the numbers: " + sum); } public static int calculateSum(int[] numbers) { int sum = 0; for (int number : numbers) { sum += number; } return sum; } } In this program, we have an array of numbers. The calculateSum method is…
View On WordPress
0 notes
arpit143blog · 1 year
Link
0 notes
arpit143blog · 1 year
Text
Java program :checks if a number is prime or not
javaCopy codeimport java.util.Scanner; public class PrimeNumber { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int number = scanner.nextInt(); scanner.close(); boolean isPrime = checkPrime(number); if (isPrime) { System.out.println(number + " is a prime number."); } else { System.out.println(number + " is not a prime…
View On WordPress
0 notes
arpit143blog · 1 year
Text
Java program :the factorial of a number
javaCopy codeimport java.util.Scanner; public class Factorial { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int number = scanner.nextInt(); scanner.close(); int factorial = calculateFactorial(number); System.out.println("Factorial of " + number + " is: " + factorial); } public static int calculateFactorial(int number)…
View On WordPress
0 notes
arpit143blog · 1 year
Text
JAVA PROGRAM : Hello world
here’s a simple Java program that prints “Hello, world!” to the console: typescriptCopy codepublic class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } } To run this program, save the code in a file named HelloWorld.java and compile it using the following command in a terminal or command prompt: Copy codejavac HelloWorld.java Then, run the…
View On WordPress
0 notes
arpit143blog · 1 year
Text
Top 10 Wild Dog Breeds in the World Wolves, foxes, coyotes, jackals…these are just some of the wild dog breeds that roam our planet.
The African wild dog is one of the world’s most endangered mammals and can be identified by its long legs and irregular fur patterns.©iStock.com/Ondrej Prosicky African Wild Dog Also called the African hunting dog, Cape hunting dog, or painted dog, its scientific name (Lycaon pictus) means “painted wolf.” It refers to its mottled fur color pattern. This canine species is native to the…
Tumblr media
View On WordPress
1 note · View note
arpit143blog · 1 year
Text
TOP 10 of the rarest animals on Earth known to man:
#10. Vaquita On the brink of extinction, the vaquita is the smallest living species of cetacean. ©Paula Olson, NOAA, Public domain, via Wikimedia Commons – License The single rarest animal in the world is the vaquita (Phocoena sinus). This porpoise lives only in the extreme northwestern corner of the Gulf of California in Mexico. Since the population was recorded at 567 in 1997, it has since…
Tumblr media
View On WordPress
2 notes · View notes