Given a positive integer n, write a Java program to calculate the sum of all positive integers from 1 to n, inclusive.
Function Signature:
public int calculateSum(int n)
An integer n where 1 <= n <= 10^4.
An integer representing the sum of all positive integers from 1 to n.
Write a Java program that computes the factorial of a positive integer entered by the user. Display the result.
Function Signature:
public int calculateFactorial(int n)
An integer n where n >= 0.
An integer representing the factorial of n. Prime Number Check
Develop a Java program that checks whether a given positive integer is a prime number or not. Display an appropriate message.
Function Signature:
public boolean isPrime(int n)
An integer n where n >= 2.
A boolean value indicating whether n is prime or not (true for prime, false for non-prime).
Write a Java program to generate the first n terms of the Fibonacci sequence and display them.
Function Signature:
public int[] generateFibonacci(int n)
An integer n where n >= 1.
An array of integers representing the first n terms of the Fibonacci sequence.
Create a Java program that draws a pattern of asterisk (*) characters based on user input for the number of rows and columns.
Function Signature:
public void drawPattern(int rows, int columns)
Two integers, rows and columns, where rows and columns are both greater than or equal to 1.
Display a pattern of asterisk (*) characters with the specified number of rows and columns.
Write a Java program that finds the largest and smallest numbers from a list of integers entered by the user. Display both results.
Function Signature:
public void findMinMax(int[] numbers)
An array of integers, numbers, where the length of the array is at least 1.
Display the largest and smallest numbers from the given list.
Write a Java program that prints the numbers from 1 to n. But for multiples of 3, print "Fizz" instead of the number, and for the multiples of 5, print "Buzz". For numbers which are multiples of both 3 and 5, print "FizzBuzz".
Function Signature:
public void fizzBuzz(int n)
An integer n where n >= 1.
Print the numbers from 1 to n based on the FizzBuzz rules.
- https://leetcode.com/problems/reverse-string/
- https://leetcode.com/problems/reverse-integer/
- https://leetcode.com/problems/missing-number/
- https://leetcode.com/problems/number-of-1-bits/
- https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
- https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/
- https://leetcode.com/problems/valid-parentheses/
- https://leetcode.com/problems/palindrome-linked-list/