0% found this document useful (0 votes)
21 views

JAVA

Java

Uploaded by

chilukuricnandan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

JAVA

Java

Uploaded by

chilukuricnandan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

PROGRAM 1:

public class ExponentialTable {

public static void main(String[] args) {

System.out.println(" Exponential Table for y = Exp[-x] ");

System.out.println("----------------------------------------------");

System.out.println("X\t0.0\t0.1\t0.2\t0.3\t0.4\t0.5\t0.6\t0.7\t0.8\t0.9");

for (int x = 0; x < 10; x++) {

System.out.print(x);

double k = 0.0;

for (int y = 0; y < 10; y++) {

System.out.printf("\t%.2f", Math.exp(-(x + k)));

k += 0.1;

System.out.println();

PROGRAM 1 OUTPUT:
PROGRAM 2:

public class ElectricityBill {

public static void main(String[] args) {

int units = 250;

double baseCharge = 100.0, surcharge;

if (units <= 100) {

baseCharge += units * 4.5;

} else if (units > 100 && units <= 300) {

baseCharge += 100 * 4.5;

baseCharge = baseCharge + (units - 100) * 5.5;

} else {

baseCharge += 100 * 4.5 + 200 * 5.5;

baseCharge = baseCharge + (units - 300) * 6.75;

if (baseCharge > 300) {

surcharge = 0.15 * baseCharge;

baseCharge = baseCharge + surcharge;

System.out.println("The amount of the bill for " + units + " units is " + baseCharge);

OUTPUT:
PROGRAM 3:

public class NumberPattern {

public static void main(String[] args) {

for (int i = 1; i <= 8; i++) {

if (i == 4 || i == 7) {

continue;

} else {

printNumberPattern(i);

private static void printNumberPattern(int num) {

for (int j = 1; j <= num; j++) {

System.out.print(num);

System.out.println();

OUTPUT:
PROGRAM 4:

public class SeriesCalculation {

public static void main(String[] args) {

double x = 10.0;

double result = calculateSeries(x);

System.out.println("The value of the series is: " + result);

private static double calculateSeries(double x) {

double result = 1.0;

for (int i = 2; i <= 10; i += 2) {

int factorial = calculateFactorial(i);

double term = Math.pow(x, i) / factorial;

if (i % 4 == 2) {

result -= term;

} else {

result += term;

return result;

private static int calculateFactorial(int n) {

int factorial = 1;

for (int j = 1; j <= n; j++) {

factorial *= j;

return factorial;
}

OUTPUT:

You might also like