Java Assignment: Name:Vaishnavi Rajesh Nagarkar PRN:10303320181124510060
Java Assignment: Name:Vaishnavi Rajesh Nagarkar PRN:10303320181124510060
PRN :10303320181124510060
Ans:
if (args.length == 0){
System.exit(0);
commandLineNumber[i] = Integer.parseInt(args[i]);
maxNumber = commandLineNumber[i];
Output :
$javac Max.java
$java Max 5 6 7 8 20
Maximum number is 20
Q2.Write a program to print the sum and average of the even and odd numbers
of first ten natural numbers.
Ans:
//program to print the sum and average of the even and odd numbers of first ten
natural numbers.
import java.io.*;
import java.util.*;
int sum = 0;
sum += 2*i;
// calculating Average
System.out.println("Sum of first " +n+ " even natural numbers is " +sum);
System.out.println("Average of first " +n+ " even natural numbars is " +(sum
/ n));
int sum = 0;
sum += ( 1 + (2*i));
// calculating Average
System.out.println("Average of first " +n+ " odd natural numbars is " + (sum
/ n));
int n = 10;
sum_avg_of_even_num(n);
sum_avg_of_odd_num(n);
Output :
Sum of first 10 even natural numbers is 110
Q3.Design a class for a bank database the database should support the following operations.
1. Deposit a certain amount into an account,
2. Withdrawing a certain amount from an account,
3. Return a value specifying the amount (i.e. balance) in an amount.
Ans :
import java.util.*;
import java.text.DecimalFormat;
double startBalance = 0;
double deposite;
double withdraw;
double totalwithdraw = 0;
double totaldeposite = 0;
startBalance=key.nextDouble();
int a=key.nextInt();
switch(a)
case 1:
break;
case 2:
withdraw=key.nextDouble();
else{
totalwithdraw += withdraw;
startBalance -= withdraw;
System.out.println("Account Balance Rs."+startBalance);
break;
case 3:
deposite = key.nextDouble();
totaldeposite += deposite;
startBalance += deposite;
break;
default:
break;
count += 1;
}
Output :
400
1.View Balance
2.Deposite
3.Withdraw
50
1.View Balance
2.Deposite
3.Withdraw
600
Total deposits Rs.600.0
Ans :
import java.util.Scanner;
import java.io.*;
String a, b ,c;
int temp;
a= input[0];
b= input[1];
//convert any string into upper case to lower case and vice versa
c=sc.nextLine();
int n = a.length();
int m = c.length();
index=a.substring(i, n).indexOf(c);
count=(index>=0)?count+1:count;
i=i+index+1;
temp=a.compareTo(b);
if(temp==0)
else if(temp>0)
else
}
Output :
Please enter two Strings:vaishnavi nagarkar
String length is 9
String length is 8
Enter Substring: ai
Ans:
import java.util.Scanner;
int m, n, c, d, a, p, q, k;
a = in.nextInt();
switch(a){
case 1:
m = in.nextInt();
n = in.nextInt();
int first[][] = new int[m][n];
first[c][d] = in.nextInt();
second[c][d] = in.nextInt();
{
for (d = 0; d < n; d++)
System.out.print(add[c][d] + "\t");
System.out.println();
break;
case 2:
int sum = 0;
m = in.nextInt();
n = in.nextInt();
first_m[c][d] = in.nextInt();
p = in.nextInt();
q = in.nextInt();
if (n != p)
else
second_m[c][d] = in.nextInt();
multiply[c][d] = sum;
sum = 0;
}
System.out.println("Product of the matrices:");
System.out.print(multiply[c][d]+"\t");
System.out.print("\n");
break;
default :
System.out.println("Invalid Operation:");
Output :
(base) ┌─[untold@parrot]─[~/Desktop/Assignment]
(base) ┌─[untold@parrot]─[~/Desktop/Assignment]
└──╼ $java Matrix
1.Addition
2.Multiplication
2 2
1 0
0 1
1 2
2 1
2 2
2 2
1.Addition
2.Multiplication
22
45
22
13
46
9 15
24 42