0% found this document useful (0 votes)
16 views

Eclipse Assignment Help

If you're struggling with your Eclipse assignment, don't worry! Java Assignment Helper is here to help. Our team of programming experts has provided a sample solution below to give you an idea of our approach, and our Java assignment helpers are available around-the-clock to assist you with any questions or doubts you may have about the assignment. Contact us at https://www.javaassignmenthelper.com/eclipse-assignment-helper/
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Eclipse Assignment Help

If you're struggling with your Eclipse assignment, don't worry! Java Assignment Helper is here to help. Our team of programming experts has provided a sample solution below to give you an idea of our approach, and our Java assignment helpers are available around-the-clock to assist you with any questions or doubts you may have about the assignment. Contact us at https://www.javaassignmenthelper.com/eclipse-assignment-helper/
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

 

Eclipse Assignment Help

For any Assignment related queries, Call us at : - +1 678 648 4277


You can mail us at : - [email protected] or
Reach us at : - https://www.javaassignmenthelper.com/
1. Write a Java program using Eclipse to calculate the area of a rectangle. The
program should prompt the user to enter the length and width of the rectangle, then
calculate and display the area.

Solution:

import java.util.Scanner;

public class RectangleArea {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
System.out.print("Enter length of rectangle: ");
double length = sc.nextDouble();
System.out.print("Enter width of rectangle: ");
double width = sc.nextDouble();
double area = length * width;
System.out.println("The area of the rectangle is " + area);
}
}

https://www.javaassignmenthelper.com/
2. Write a Java program using Eclipse to find the factorial of a number. The
program should prompt the user to enter a number, then calculate and display the
factorial.

Solution:

import java.util.Scanner;

public class Factorial {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
int fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i;
}
System.out.println("The factorial of " + num + " is " + fact);
}
}

https://www.javaassignmenthelper.com/
3. Write a Java program using Eclipse to check if a given number is prime or not.
The program should prompt the user to enter a number, then check and display
whether the number is prime or not.

Solution:

import java.util.Scanner;

public class PrimeNumber {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
boolean isPrime = true;
if (num == 1 || num == 0) {
isPrime = false;
}
else {
for (int i = 2; i <= Math.sqrt(num); i++) {
if (num % i == 0) {
isPrime = false;
https://www.javaassignmenthelper.com/
break;
}
}
}
if (isPrime) {
System.out.println(num + " is a prime number");
}
else {
System.out.println(num + " is not a prime number");
}
}
}

https://www.javaassignmenthelper.com/
4. Write a Java program using Eclipse to find the sum of the digits of a number. The
program should prompt the user to enter a number, then calculate and display the
sum of its digits.

Solution:

import java.util.Scanner;

public class SumOfDigits {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
int sum = 0;
while (num != 0) {
sum += num % 10;
num /= 10;
}
System.out.println("The sum of the digits is " + sum);
}
}
https://www.javaassignmenthelper.com/
5. Write a Java program using Eclipse to sort an array of integers in ascending
order. The program should prompt the user to enter the size and elements of the
array, then sort and display the sorted array.

Solution:

import java.util.Scanner;
import java.util.Arrays;
public class SortArray {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of the array: ");
int size = sc.nextInt();
int[] arr = new int[size];
System.out.println("Enter the elements of the array: ");
for (int i = 0; i < size; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
System.out.println("The sorted array is: " + Arrays.toString(arr));
}}
https://www.javaassignmenthelper.com/

You might also like