Posts

Showing posts from October, 2025

Week4 java

  Write a program that creates a user interface to perform integer divisions. The user enters two numbers in the text fields, Num1 and Num2.The division of Num1 and Num2 is displayed in the Result field when the Divide button is clicked. If Num1 or Num2 were not an integer, the program would throw a NumberFormatException. If Num2 were Zero, the program would throw an Arithmetic Exception Display the exception in a message dialog box. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class DivisionCalculator extends JFrame implements ActionListener { JLabel inputLabel1, inputLabel2, resultLabel; JTextField input1, input2, result; JButtondivideButton;     public DivisionCalculator() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout());         inputLabel1 = new JLabel("Welcome"); setSize(800, 400);         inputLabel1 = new JLabel("Enter Number1");         add(inputLa...

Week13

 import java.io.File;   public class DisplayFileExample   {   public void printFileNames(File[] a, int i, int lvl)   {   // base case of the recursion   // i == a.length means the directory has    // no more files. Hence, the recursion has to stop   if(i == a.length)   {   return;   }   // checking if the encountered object is a file or not   if(a[i].isFile())   {   System.out.println(a[i].getName());   }   // recursively printing files from the directory   // i + 1 means look for the next file   printFileNames...