Question

om me insert e Search - Assignment - Word Design Layout References Mailings Review Lucida Sans Typ 11 - A A A A - BIU XX A.D.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Program for Abundant Number :-

package abundantno; import java.util.*; public class AbundantNo { public static void main(String[] args) { System.out.println("Enter the number: "); Scanner sc = new Scanner(System.in); int nbr = sc.nextInt(); AbundantNo a = new AbundantNo(); if(a.isAbundant(nbr)) System.out.println("The number " + nbr + " is Abundant."); else System.out.println("The number " + nbr + " is not Abundant."); } public static boolean isAbundant(int number) { int sum = 0; for (int i=1; i<=Math.sqrt(number); i++) { if (number%i==0) { if (number/i == i) sum = sum + i; else { sum = sum + i; sum = sum + (number / i); } } } sum = sum - number; if (sum>number) return true; else return false; } } 

2. Program for Fibonacci Series :-

  package fibonaccinumber; import java.util.*; public class FibonacciNumber { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int answer; int n; System.out.println("Enter ith element: "); n = sc.nextInt(); answer = fibonacci(n); System.out.println("The "+n+"th element in Fibonacci series is: "+answer); } public static int fibonacci(int n){ if(n == 0) return 0; else if(n == 1) return 1; else return fibonacci(n-1)+fibonacci(n-2); } } 

Output -

Add a comment
Know the answer?
Add Answer to:
om me insert e Search - Assignment - Word Design Layout References Mailings Review Lucida Sans...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Let’s work together to develop a call tree for the execution of the following recursive method....

    Let’s work together to develop a call tree for the execution of the following recursive method. (The method allows us to recursively generate the nth integer in the Fibonacci sequence, although you don’t need to be familiar with that sequence to understand this problem.) public static int fib(int n) { if (n == 0 || n == 1) { return 1; } else { int prev1 = fib(n - 2); int prev2 = fib(n - 1); return prev1 + prev2;...

  • Here is the assignment: Fibonacci or Prime number iterator: Design a menu driven program that performs...

    Here is the assignment: Fibonacci or Prime number iterator: Design a menu driven program that performs the user’s choice of the following functions the program exits should also be a user’s choice. Menu Item 1: Fibonacci number iterator, here you are to define an iterator class named FibonacciIterator for iterating Fibonacci numbers. The constructor takes an argument that specifies the limit of the maximum Fibonacci number. For example, prompt the user for size, use the size to call FibonacciIterator(“user input”)...

  • Fibtester: package fibtester; // Imported to open files import java.io.File; // Imported to use the exception...

    Fibtester: package fibtester; // Imported to open files import java.io.File; // Imported to use the exception when files are not found import java.io.FileNotFoundException; // Imported to write to a file import java.io.PrintWriter; // Imported to use the functionality of Array List import java.util.ArrayList; // Imported to use the exceptions for integer values import java.util.NoSuchElementException; // Imported to use when the array is out of bounds import java.lang.NullPointerException; // Imported to take input from the user import java.util.Scanner; public class FibTester...

  • Write a method called printReverse() that takes a string and uses recursion to print the contents...

    Write a method called printReverse() that takes a string and uses recursion to print the contents of the string in reverse order. The string itself should not be reversed; it must be left in its original form. The method has the following header:   void printReverse(String s, int i) where s is a reference to the string, and i is an integer parameter that you may use as you see fit. You do not need to code up this method as...

  • Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If...

    Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If you do actually win the lottery, please be sure to give back to your alma mater, Orange Coast College. We will be happy to put your name on the building!**) Ok, time to get real. The Fantasy 5 (TM) lottery is a game in which 5 numbers from 1 to 36 are randomly drawn by the State of California. If you correctly guess all...

  • Lab 1.java only Goal: This lab will give you experience with defining and using classes and...

    Lab 1.java only Goal: This lab will give you experience with defining and using classes and fields, and with conditionals and recursive functions. Getting Started --------------- Read the Fraction.java class into a text editor and compile it filling in the command javac -g Fraction.java. The program should compile without errors. In a shell window, run the program using "java Fraction". The program should run, although it will print fractions in a non-reduced form, like 12/20. Part I: Constructors (1 point)...

  • Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and...

    Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and implementation HighArray class and note the attributes and its methods.    Create findAll method which uses linear search algorithm to return all number of occurrences of specified element. /** * find an element from array and returns all number of occurrences of the specified element, returns 0 if the element does not exit. * * @param foundElement   Element to be found */ int findAll(int...

  • Make a program using Java that asks the user to input an integer "size". That integer...

    Make a program using Java that asks the user to input an integer "size". That integer makes and prints out an evenly spaced, size by size 2D array (ex: 7 should make an index of 0-6 for col and rows). The array must be filled with random positive integers less than 100. Then, using recursion, find a "peak" and print out its number and location. (A peak is basically a number that is bigger than all of its "neighbors" (above,...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • Please write a code in Java where it says your // your code here to run...

    Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT