Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

View RSS Feed

All Blog Entries

  1. Math Class Methods

    There are many built in methods we can use to conduct mathematical operations to numbers. Here are some of them.

    class Class1{
    	public static void main(String args[]){
    		//How far number is from zero.
    		System.out.println(Math.abs(-26.7));
    		//Rounds number up.
    		System.out.println(Math.ceil(7.4));
    		//Rounds number down.
    		System.out.println(Math.floor(7.8));
    		//Greater of the two numbers.
    		System.out.println(Math.max(8.6,
    ...
    Categories
    Uncategorized
  2. Do While Loop

    We use the Do While Loop when we want to run a set of instructions before testing to see if a condition is true. The difference between a Do While Loop and a While Loop is that the While Loop tests the condition first and then runs the instructions.

    class Class1{
    	public static void main(String args[]){
    		int counter = 0;
    		do{
    			System.out.println(counter);
    			counter++;
    		}while(counter <= 10);
    	}
    }
    ...
    Categories
    Uncategorized
  3. Compound Interest Calculator

    Compound interest can be calculated with the following formula.

    A = Amount
    P = Principal
    R = Rate
    n = Years

    A=P(1+R)^n

    We can calculate the amount in Java as shown below. We currently know the principal (10,000) and the rate (1%). The years can change depending on how much information we want. In this application, we'll just use 20.

    class Class1{
    	public static void main(String args[]){
    		double amount;
    ...
    Categories
    Uncategorized
  4. For Loops

    The For Loop is probably the most common loop used in any programming language. Here's how it works in Java.

    class Class1{
    	public static void main(String args[]){
    		for(int counter=1; counter<=10; counter++){
    			System.out.println(counter);
    		}
    	}
    }

    The For Loop takes three arguments: where you want it to start, where you want it to end, and how you'd like to increment the counter. Take a look at the below ...
    Categories
    Uncategorized
  5. Simple Averaging Program

    What this application does is collects a number of inputs from the user via a scanner. These inputs are numbers. They are then averaged and the average is outputted. Pretty simple stuff.

    import java.util.Scanner;
    class Class1{
    	public static void main(String args[]){
    		Scanner input = new Scanner(System.in);
    		int total = 0;
    		int grade;
    		int average;
    		int counter = 0;
    		int numGrades = 10;
     
    		System.out.println("Please
    ...
    Categories
    Uncategorized
Page 4 of 13 FirstFirst ... 23456 ... LastLast