Java Variable Types

A variable gives us named capacity that our code can control. Every variable in Java has a particular sort, which decides the size and format of the variable’s memory; the scope of values that can be put away inside that memory; and the set of operations that can be connected to the variable. You must … Read more

Java Program to Check Armstrong Number

public class JavaEx { public static void main(String[] args) { int num = 370, number, temp, total = 0; number = num; while (number != 0) { temp = number % 10; total = total + temp*temp*temp; number /= 10; } if(total == num) System.out.println(num + ” is an Armstrong number”); else System.out.println(num + ” … Read more

Java Program to Add Two Complex Numbers

  public class ComplexNumber{ double real, img; ComplexNumber(double r, double i){ this.real = r; this.img = i; } public static ComplexNumber sum(ComplexNumber c1, ComplexNumber c2) { ComplexNumber temp = new ComplexNumber(0, 0); temp.real = c1.real + c2.real; temp.img = c1.img + c2.img; return temp; } public static void main(String args[]) { ComplexNumber c1 = new … Read more

Java Program to Calculate Compound Interest

public class JavaExm { public void calculate(int p, int t, double r, int n) { double amount = p * Math.pow(1 + (r / n), n * t); double cinterest = amount – p; System.out.println(“Compound Interest after ” + t + ” years: “+cinterest); System.out.println(“Amount after ” + t + ” years: “+amount); } public … Read more