Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
This is a Java Program to Accept Array Elements and Calculate Sum. An array is a group of like-typed variables that are referred to by a common name. Arrays of any type can be created and may have one or more dimensions. Aspecific element in an array is accessed by its index.
Enter the size of array and then enter all the elements of that array. Now we calculate the sum of elements of the array with the help of for loop. 
Here is the source code of the Java Program to Accept Array Elements and Calculate Sum. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

File Name - AddArray.java


Output - java Add

Read More
An abstract class is a class that is declared abstract — it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. An abstract class may have static fields and static methods. When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, then the subclass must also be declared abstract.
An abstract method is a method that is declared without an implementation (without braces and followed by a semicolon), like this:
abstract void sum(int a, int b);

Consider using abstract classes if any of these statements apply to your situation:
  1. You want to share code among several closely related classes.
  2. You expect that classes that extend your abstract class have many common methods or fields or require access modifiers other than public (such as protected and private).
  3. You want to declare non-static or non-final fields. This enables you to define methods that can access and modify the state of the object to which they belong.
Example -
File name - Abstarct_Bank.java


Output -


Read More
In this programme we are taking details of employee form the user and print them.

File name - Employee.java





Output - java Employee


Read More
Write a Java program to input amount from user and print minimum number of notes (Rs. 500, 100, 50, 20, 10, 5, 2, 1) required for the amount. How to the minimum number of notes required for the given amount in java programming. Program to find minimum number of notes required for the given denomination. Logic to find minimum number of denomination for a given amount in java program.

File Name- Currency.java



Output -



Read More
Input any four number from user and write a java program to add first number with fourth number and second number with third number.


File Name - dsum.java


Output -


Read More
A Constructor with arguments(or you can say parameters) is known as Parameterized constructor. 

File name - ConstructorStudent.java


Output -




Read More
A constructor in Java is a special method that is used to initialise objects. The constructor is called when an object of a class is created. It can be used to set initial values for object attributes.
Java compiler automatically creates a default constructor (Constructor with no arguments) in case no constructor is present in the java class. Following are the motive behind a default constructor.

  • Create the Object
  • Call the super class constructor()
  • Initialize all the instance variables of the class object.

File Name - Constructor_test.java



Output -



Read More
In this program, you'll learn to check whether an alphabet is a vowel or a consonant switch case in Java.

File Name - vowel_or_consonent.java


Output - 



Read More
In this program we will print HELLO ten times with the count using while loop.

File Name - Hello.java



Output - 



Read More
In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories:
  • subclass (child) - the class that inherits from another class
  • superclass (parent) - the class being inherited from

To inherit from a class, use the extends keyword

In the example below, the Circle class (subclass) inherits the attributes and methods from the Area class (superclass):

File Name - Final_area.java




Output -



Read More

Java program to find the largest of three numbers and then print it. If the numbers are unequal then "numbers are not distinct" is printed. Comparison operator '>' is used to compare two numbers. To find the largest number out of a given numbers you can also use an array.

File Name - largestnumber.java



Output -


Read More
Percent means percent (hundreds), i.e., a ratio of the parts out of 100. The symbol of a percent is %. We generally count the percentage of marks obtained, return on investment etc. The percentage can go beyond 100% also.
For Example, assuming that we have total and a part. So we say what part is what percent of total and should be calculated as :
percentage = ( part / total ) × 100

Algorithm

  • 1. Collect values for part and total
  • 2. Apply formula { percentage = ( part / total ) × 100 }
  • 3. Display percentage
To calculate average and percentage marks of a students, you have to ask to the user to enter marks obtained in some subjects (say 5). Place summation of 5 subject's marks in a variable say sum and place sum/5 in a variable say avg then place sum/500*100 in a variable say perc, then display the result on the output screen.


File Name -  Marks.java




Output -


Read More
Java program to check if a number is odd or even: if a number is divisible by two then it is even, otherwise, it is odd. We use modulus operator to find remainder in our program. For an even number remainder will be zero when it is divided by two and will be one for an odd number.

File Name - evenorodd.java



Output - 



Read More
Area of a circle and Area of rectangle can simply be evaluated using following formula.
Area = pi * r2
where r is radius of circle 
Area = l*b
where l is length and b is breadth.

File name - Area.java

class Area
{
public static void main(String args[])
{
int Circle_area, Rect_area, l, b, r;
l=10;
b=5;
r=13;

Circle_area=2*r*r;
Rect_area=l*b;

System.out.println("Area of Circle is "+Circle_area);
System.out.println("Area of Rectangle is "+Rect_area);
}
}



Output-


Area of Circle is 338
Area of Rectangle is 50

Read More

About Me

My photo
I work as an Analyst in HCL Technologies. Android App Development is my hobby. As a passionate technology lover, you need to keep yourself updated with trending technologies. The best way to learn and stay up to date is simply to do something creative. I’ve a number of small personal app projects and each one have been rewarding and useful in one way or the other.