Java

 

class AllBlocks Demo

public static void main(String args[]) { String citylist[] = {"Ahmedabad", "Baroda", "Rajkot", "Surat");

int numerator = 15, denominator = 0, answer:

System.out.println("Statement to be executed before try block");

try {

System.out.println("Begining of try block...");

System.out.printin(citylist[5]); // Generates ArrayIndexOutOfBoundsException answer numerator / denominator; // Generates ArithmeticException System.out.println("End of try block...");

}

catch(ArrayindexOutOfBoundsException eobj) {

} System.out.println("Within first catch block, exception caught:" + eobj);

catch(ArithmeticException eobj) {

System.out.println("Within second catch block, exception caught:" + eobj); }

catch(Exception eobj) {

System.out.println("Within last catch block, exception caught:" + eobj); //Generic block

System.out.println("This part of code will always get executed"); }

}

System.out.println("End of Program...");

finally {

1

}

}

class ArrayAvg

public static void main(String[] s), {

double numbers [] = { 10.5, 20.6, 30.8, 15.5, 17.3, 25.5, 27.7 , 20, 30 18.5);

byte ctr

double sum=0, avg;

System.out.printin ("list of numbers is"); for (ctr=0; ctr<10; ctr++)

System.out.printin (numbers[ctr]); sum=sum+numbers [etr]

avg - sum/101 System.out.println ("\nAverage of above numbers is" + avg);

}

// main

// class

class PrintLine

{

static void printline()

{

for (int i=0; i<40; i ++) System.out.print (^ prime =^ prime ); System.out.println();

}

static void printline(int n)

{

for (int i=0; i<n; i ++) System.out.print('#'); System.out.println();

}

static void printline(char ch, int n)

{

for (int i=0; i<n; i ++) System.out.print(ch); System.out.println();

}

} // end class PrintLine

public class polyDemo

-{

public static void main(String[] s)

{

PrintLine.printline(); PrintLine.printline(30);

PrintLine.printline('+',20);

} // end PolyDemo class

} // end main

// principal amount in rupees

// interest rate in percentage

// number of years // maturity amount

public static void main(String[] args) {

/* declare variables */

double principal;

double rate;

public class Interest

{

// interest amount

double duration; double maturity;

double interest;

/* computations. */ principal - 17000; rate = 9.50; duration= 3 :

interest - principal * duration * rate / 100; // compute interest amount maturity = principal + interest; // compute maturity amount

/* display results */ System.out.println("Principal amount: " + principal + "Rupees");

System.out.println("Deposit for duration of " + duration + " years"); System.out.println("Interest Rate: " + rate + "%");

System.out.println("Interest amount: " + interest + "Rupees"); System.out.println("Maturity amount:" + maturity + " Rupees");

} // end of main()

} // end of class Interest

Comments

Popular posts from this blog

Hotel Billing Management Software By Suryanshsk

Develope Snake game using Html Code

Write a program that prompts the user to input number of calls and calculate the monthly telephone bills as per the following rule: Minimum Rs. 200 for up to 100 calls. Plus Rs. 0.60 per call for next 50 calls. Plus Rs. 0.50 per call for next 50 calls. Plus Rs. 0.40 per call for any call beyond 200 calls.