Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Constructor Demo

public class ArithmeticDemo {
    public static void main(String[] args) {
        
        /* Here are some variable declarations.
        Each int is intialized with a value.
         */
      
      int numberOfPasses; 
      
        int x = 13;
        int y = 5;
        int z = x + y;
        
        // display sum, difference, product, quotient, 
        // and remainder. 
        System.out.println(z);
        System.out.println(x + y);
        System.out.println(x - y);
        System.out.println(x * y);
        System.out.println(x / y);
        System.out.println(x % y);
        
    }
}

ConstructorDemo

import java.util.Random;
import java.math.BigInteger;
import java.net.HttpCookie;
import java.util.GregorianCalendar;

/*
 * Demonstrates the creation of objects and their initialization
 * using constructors.
 *
 * @author Benjamin Shepard
 * @version September 13, 2017
*/

public class ConstructorDemo {
    public static void main(String[] args) {
        Random rand = new Random();
        BigInteger num = new BigInteger("875932754324");
        HttpCookie cookie = new HttpCookie("username", "bshepard");
        
        GregorianCalendar today = new GregorianCalendar();
        GregorianCalendar bDay = new GregorianCalendar(2000, 9, 26);
        
    }
}

Hello Tyler

public class HelloWorld{
    public static void main(String[] args){
        
        System.out.println("Hello there Tyler!\nHow are you today?");
    }
}

Arithmetic Demo

public class ArithmeticDemo{
    public static void main(String[] args){
        int x = 3;
        int y = 5;
        
        // displays sum, difference, product, quotient, and remainder
        System.out.println(x + y);
        System.out.println(x - y);
        System.out.println(x * y);
        System.out.println(x / y);
        System.out.println(x % y);
    }
}

Compile and Execute Java Online

import java.util.Scanner;
public class LoanDemo
{
   // start main method
   public static void main(String[] args)
   {          
       // variables declaration
       double loanAmount;
       int loanPeriod;
       double startingIR = 5.0;
       double endingIR = 8.0;
       double increment = 1.0 / 8.0;
      
       // create an object for Scanner class
       Scanner input = new Scanner(System.in);
      
       // prompt the user to enter the loan amount
       System.out.print("Loan Amount: ");
       loanAmount = input.nextDouble();
      
       /* prompt the user to enter the loan period in number of years */
       System.out.print("Number of Years: ");
       loanPeriod = input.nextInt();
          
       // display the resultant table's heading
       System.out.printf("\n%-20s%-20s%-20s\n", "Interest Rate", "Monthly Payment", "Total Payment");
      
       /* display the monthly and total payments for each interest rate starting from 5% to 8% with an increment of 1/8 */
       for(double interestRate = startingIR; interestRate <= endingIR; interestRate += increment)
       {
           // compute monthly interest rate
           double monthlyIR = interestRate / 1200;
          
           // compute the monthly payment
           double monthlyPayment = loanAmount * monthlyIR    / (1 - 1 / Math.pow(1 + monthlyIR, loanPeriod * 12));
          
           // compute the total payment
           double totalPayment = monthlyPayment * loanPeriod * 12;
          
           // display the results
           System.out.printf("%-20.3f%-20.2f%-20.2f\n", interestRate, monthlyPayment, totalPayment);
       } // end for
   } // end of main method
} // end of LoanDemo class

Compile and Execute Java Online

import java.util.Scanner;
public class LoanDemo
{
   // start main method
   public static void main(String[] args)
   {          
       // variables declaration
       double loanAmount;
       int loanPeriod;
       double startingIR = 5.0;
       double endingIR = 8.0;
       double increment = 1.0 / 8.0;
      
       // create an object for Scanner class
       Scanner input = new Scanner(System.in);
      
       // prompt the user to enter the loan amount
       System.out.print("Loan Amount: ");
       loanAmount = input.nextDouble();
      
       /* prompt the user to enter the loan period in number of years */
       System.out.print("Number of Years: ");
       loanPeriod = input.nextInt();
          
       // display the resultant table's heading
       System.out.printf("\n%-20s%-20s%-20s\n", "Interest Rate", "Monthly Payment", "Total Payment");
      
       /* display the monthly and total payments for each interest rate starting from 5% to 8% with an increment of 1/8 */
       for(double interestRate = startingIR; interestRate <= endingIR; interestRate += increment)
       {
           // compute monthly interest rate
           double monthlyIR = interestRate / 1200;
          
           // compute the monthly payment
           double monthlyPayment = loanAmount * monthlyIR    / (1 - 1 / Math.pow(1 + monthlyIR, loanPeriod * 12));
          
           // compute the total payment
           double totalPayment = monthlyPayment * loanPeriod * 12;
          
           // display the results
           System.out.printf("%-20.3f%-20.2f%-20.2f\n", interestRate, monthlyPayment, totalPayment);
       } // end for
   } // end of main method
} // end of LoanDemo class

Compile and Execute Java Online

public class B{
    void disp()
    {
        System.out.println("Inside B class");
    }
     
}

Compile and Execute Java Online

public class HelloWorld{

     public static void main(String []args){
        System.out.println("Hello World");
     }
}

exempel03_01

// fält
package exempel03_01;

public class Exempel03_01 {
    public static void main(String[] args) {
        double tid[] = {10.12, 9.88, 9.92};
        System.out.println("Fältet innehåller följande tider: ");
        System.out.println(tid[0] + "\t" + tid[1] + "\t" + tid[2]);
    }
}

Compile and Execute Java Online

public class HelloWorld{

     public static void main(String []args){
        System.out.println("Hello World");
        
        Newthing topo = new Newthing();
        System.out.println(topo.name);
     }
     
     public class Newthing {
         String name;
         String talk;
         
         public Newthing(String name, String talk) {
             this.name = name;
             this.talk = talk;
         }
     }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.