Professional Documents
Culture Documents
java execution:
1. cd\
2. cd program files/java/jdk-12.0.1/bin
3. javac Slip22a.java
4. java Slip22a
-----------------------------------------------------------------------------
a.1
import java.lang.*;
public class Slip22a
{
public static void main(String[] args)
{
int num = 6;
long factorial = multiplyNumbers(num);
System.out.println("Factorial of " + num + " : " + factorial);
}
public static long multiplyNumbers(int num)
{
if (num >= 1)
return num * multiplyNumbers(num - 1);
else
return 1;
}
}
__________________________________________________________________________
a.2
import java.io.*;
import java.util.*;
class Slip22B
{
public static void main(String args[]) throws IOException
{
Scanner br = new Scanner(System.in);
System.out.println(" 1.Press 1 Create File\n 2.Press 2 Rename a File\n 3.Press 3
Delete a File\n 4.Press 4 Display Path of a File");
System.out.print("Enter File Name:");
String str = br.nextLine();
File file = new File(str);
System.out.println("Select The Above Option: ");
int num = br.nextInt();
switch(num)
{
case 1 :
if (file.createNewFile())
{
System.out.println("File created : " + file.getName());
}
else
{
System.out.println("File already exists.");
}
break;
case 2 :
System.out.println("Enter New File Name:");
String newone =br.nextLine();
File newfile =new File(newone);
if(file.renameTo(newfile))
{
System.out.println("File renamed");
}
else
{
System.out.println("Sorry! the file can't be renamed");
}
break;
case 3 :
if (file.delete())
{
System.out.println("Deleted the file: " + file.getName());
}
else
{
System.out.println("Failed to delete the file.");
}
break;
case 4 :
System.out.println("File Location : " +file.getAbsolutePath());
break;
default :
System.out.println("Wrong Number ..!");
break;
}
}
}
_______________________________________________________________________
Q.22.B
Python
22…….a
________________________________________________________________________
class RepeatString:
def _init_(self, string, n):
self.string = string
self.n = n
def _mul_(self, other):
return self.string * other.n
def _str_(self):
return self.string* self.n
# Example usage
string_obj = RepeatString(input("Enter a string: "), int(input("Enter number of
repetition: ")))
print(string_obj)
print(string_obj * string_obj)
_________________________________________________________________________
22….b
def bubble_sort(arr):
n = len(arr)
return arr