Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** * Write a description of class Project6 here. * * @author () * @version (a version number or a date) */ import java.io.File; import

/** * Write a description of class Project6 here. * * @author () * @version (a version number or a date) */ import java.io.File; import java.io.PrintWriter; import java.io.FileNotFoundException; import java.util.Scanner; public class CountDigits { public static int countDigits(int n, int d) { // Base case if(n <= 0) return 0; // Recursive case else{ int r = n%10; if(r == d) { return 1+ countDigits(n/101, d); } else{ return countDigits(n/101, d); } } } public static void main(String[] args) throws FileNotFoundException { //Opening file Scanner sc = new Scanner(new File("countDigits.txt")); // Reading an number int n = sc.nextInt(); // Reading digit int d = sc.nextInt(); sc.close(); // calling countDigit function int count = countDigits(n, d); System.out.println("Number of times "+d+" is in "+n+" : "+count); } } class Pyramids { public static int pyramid(int n) { if(n == 0) { return 0; } else { return n + pyramid(n-1); } }

public static void main(String[] args) throws FileNotFoundException { try { Scanner fin = new Scanner(new File("pyramid.txt")); if(fin.hasNextInt()) { System.out.println(pyramid(fin.nextInt())); } fin.close(); } catch (FileNotFoundException e) { System.out.println("pyramid.txt does not exists"); } } }

class FillArray { private static Scanner sc = new Scanner(System.in); public static void read(int[] arr, int n) { if(n <= 0) { return; } arr[n-1] = sc.nextInt(); read(arr, n-1); }

public static void main(String[] args) throws FileNotFoundException { // Opening fillArray.txt Scanner inFile = new Scanner(new File("fillArray.txt"));;

// Reading n values int n = inFile.nextInt();

// Creating an array int[] arr =new int[n]; // Taking user input System.out.println("Enter "+n+" integers"); read(arr, n); // Output on the terminal and output file "output.txt" PrintWriter out = new PrintWriter("output.txt"); for(int i=0; i

I need to have one main method that sends the recursive method what it needs. The recursive method will return the results to the main. I also need a menu that lets the user choose the project to use. Menu should have all 3 programs to choose from. I attached the java file of the 3 seperate projects.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions