ANSHMAIN
ANSHMAIN
import java.util.Scanner;
class Number {
int n;
String numtype;
void input() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
n = sc.nextInt();
}
void checkType() {
int sum = 0;
for (int i = 1; i <= n; i++) {
if (n % i == 0) {
sum += i;
}
}
if (sum == 2 * n) {
numtype = "perfect";
} else if (sum > 2 * n) {
numtype = "abundant";
} else {
numtype = "deficient";
}
}
void display() {
System.out.println("Number: " + n);
System.out.println("Number Type: " + numtype);
}
public static void main(String[] args) {
Number num = new Number();
num.input();
num.checkType();
num.display();
}
}
PROGRAM-2:-
import java.util.*;
public class check
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
if (num < 0) {
System.out.println(num + " is not a Pronic Number” };
else {
boolean isPronic = false;
for (int i = 0; i * (i + 1) <= num; i++) {
if (i * (i + 1) == num) {
isPronic = true;
break;
}
}
if (isPronic) {
System.out.println(num + " is a Pronic Number.");
} else {
System.out.println(num + " is not a Pronic Number.");
}
}
PROGRAM-3:-
import java.util.Scanner;
if (isDisarium(num)) {
System.out.println(num + " is a Disarium number.");
} else {
System.out.println(num + " is not a Disarium number.");
}
}
import java.util.Scanner;
import java.util.Scanner;
public class p6 {
String pigLatin;
if (firstVowelIndex == -1) {
pigLatin = word + "AY";
} else if (firstVowelIndex == 0) {
pigLatin = word + "AY";
}
else {
String firstPart = word.substring(firstVowelIndex);
String secondPart = word.substring(0, firstVowelIndex);
pigLatin = firstPart + secondPart + "AY";
}
System.out.println("Pig Latin: " + pigLatin);
}
}
PROGRAM-7:-
}
PROGRAM-8:-
import java.util.*;//importing util package
class FilePath//class declaration
{
void Extenions()//function prototype
{ Scanner sc=new Scanner(System.in);//object of the scanner class
System.out.println("Enter the file path");
String n=sc.nextLine();//taking the input from the user
int c=0;//to count the number of "/" in the filepath
int sl=n.lastIndexOf('/');//to store the location of slash
int dl=n.indexOf('.');//to store the location of dot
char ch;//to store characters
if(n.indexOf('/')==-1&&n.indexOf('.')==-1&&n.indexOf(':')==-1)
//checking if the File Path is valid .
{
System.out.println("Invalid File Path");
System.exit(0);
//Terminating the program if the File Path is invalid
}
System.out.println("Path:"+n.substring(0,sl));
//Printing the File Path
System.out.println("File name:"+n.substring(sl+1,dl));
//Printing the File name
System.out.println("Extension:"+n.substring(dl+1,n.length()));
//Printing the File Extension
}
}
PROGRAM-9:-
import java.util.Scanner;
class library {
int acc_num;
String title;
String author;
void input() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter accession number: ");
acc_num = scanner.nextInt();
scanner.nextLine(); // Consume newline left by nextInt()
System.out.print("Enter title: ");
title = scanner.nextLine();
System.out.print("Enter author: ");
author = scanner.nextLine();
}
void compute() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of days late: ");
int daysLate = scanner.nextInt();
int fine = daysLate * 2;
System.out.println("Fine charged: Rs. " + fine);
}
void display() {
System.out.println("Accession Number\t\tTitle\t\tAuthor");
System.out.println(acc_num + "\t\t" + title + "\t\t" + author);
}
import java.util.Scanner;
System.out.println("Digit\tFrequency");
//Print only present digits
for (int i = 0; i < 10; i++) {
if (frequency[i] > 0) {
System.out.println(i + "\t\t" + frequency[i]);
}
}
}
}
PROGRAM-11:-
import java.util.Scanner;
public class Friendweightsorter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
final int NUM_FRIENDS = 20;
String[] name = new String[NUM_FRIENDS];
double[] weight = new double[NUM_FRIENDS];
for (int i = 0; i < NUM_FRIENDS; i++) {
System.out.print("Enter name of friend " + (i + 1) + ": ");
name[i] = scanner.nextLine();
System.out.print("Enter weight of " + name[i] + ": ");
weight[i] = scanner.nextDouble();
scanner.nextLine();
}
scanner.close();
for (int i = 0; i < NUM_FRIENDS - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < NUM_FRIENDS; j++) {
if (weight[j] < weight[minIndex]) {
minIndex = j;
}
}
double tempWeight = weight[minIndex];
weight[minIndex] = weight[i];
weight[i] = tempWeight;
void polygon() {
for (int i = 1; i <= 3; i++) { // Outer loop for rows
for (int j = 1; j <= i; j++) { // Inner loop for asterisks in each row
System.out.print("*");
}
System.out.println(); // Newline after each row
}
}
System.out.println("Menu:");
System.out.println("1. Generate and display Fibonacci series");
System.out.println("2. Find sum of digits of an integer");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
int count = 10; // Generate first 10 terms
int num1 = 0, num2 = 1;
System.out.print("Fibonacci Series: ");
for (int i = 1; i <= count; ++i) {
System.out.print(num1 + " ");
int num3 = num1 + num2;
num1 = num2;
num2 = num3;
}
System.out.println();
break;
case 2:
System.out.print("Enter an integer: ");
int number = scanner.nextInt();
int sum = 0;
import java.util.Scanner;
public class stdcode {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
public class a {
import java.util.*;
class Matrix
{
int m[][] = new int[3][3];
void getdata() {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 3; i++)
{
for (int k = 0; k < 3; k++)
{
System.out.println("Enter the Element of row no." + (i + 1) + " and column
no." + (k + 1));
m[i][k] = sc.nextInt();
}
}
System.out.println("The original Matrix is:-");
for (int i = 0; i < 3; i++)
{
for (int k = 0; k < 3; k++)
{
System.out.print(m[i][k] + "\t");
}
System.out.println();
}
}
void rowsum()
{
int sum;
for (int i = 0; i < 3; i++)
{
sum = 0;
for (int k = 0; k < 3; k++)
{
sum = sum + m[i][k];
}
System.out.println("Sum of row no." + (i + 1) + " is " + sum);
}
}
void colsum()
{
int sum;
for (int i = 0; i < 3; i++)
{
sum = 0;
for (int k = 0; k < 3; k++)
{
sum = sum + m[k][i];
}
System.out.println("Sum of column no." + (i + 1) + " is " + sum);
}
}
// Bubble Sort
for (int i = 0; i < 20 - 1; i++) {
for (int j = 0; j < 20 - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
// Swap arr[j] and arr[j+1]
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
// Selection Sort
for (int i = 0; i < n - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < n; j++) {
if (animals[j].compareTo(animals[minIndex]) < 0) {
minIndex = j;
}
}
System.out.println("Enter 5 words:");
for (int i = 0; i < 5; i++) {
words[i] = sc.nextLine();
}