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

Empty Program

public class EmptyProgram {
    public static void main(String []args) {
        
        
    }
}

CompositeScore

import java.util.Scanner;
import java.text.DecimalFormat;
public class CompositeScore{

     public static void main(String []args){
         System.out.println("Enter three exam scores: ");
         Scanner sc = new Scanner(System.in);
         int exam1 = sc.nextInt();
         int exam2 = sc.nextInt();
         int exam3 = sc.nextInt();
         int min = Math.min(exam1, Math.min(exam2, exam3));
         
         int sum = exam1 + exam2 + exam3 - min;
         double avg = sum / 2;
         double score = new DecimalFormat(0#.#);
         
         
         System.out.println("Composite Score: " + score);
         
     }
}

testing a consile

public class HelloWorld{

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

Cat can bark

import java.util.*;

public class MainClass
{
    static interface Animal { void bark(); }
    static class Dog implements Animal {
        private String name;
        public Dog(String name) { this.name = name; }
        public void bark() {
            System.out.println("<" + name + "> Wouaf!");
        }
    }
    static class Cat implements Animal {
        private String name;
        public Cat(String name) { this.name = name; }
        public void bark() {
            System.out.println("<" + name + "> Meow!");
        }
    }
    
    public static void main(String[] args)
    {
        List<Dog> dogs = new ArrayList<Dog>();
        addTo(dogs, new Dog("Medor"));
        addTo(dogs, new Cat("Persy")); // uh!?
        addTo(dogs, new Dog("Rex"));
        
        System.out.println("C'mon dogs, let's bark:");
        for (Animal animal : dogs) {
            animal.bark();
        }
    }
    
    private static <T> void addTo(List list, T animal)
    {
        list.add(animal);
    }
}

J8- Basics

import java.util.Date;
import java.util.List;
import java.util.ArrayList;

public class HelloWorld{

     public static void main(String []args)  throws  Exception{
        System.out.println("Hello World");
        
        
    
        Stock s = new Stock().setId("1").setCompanyName("Sapinet");
        s.setAmount(22.00).setPurchaseDate(new Date());
        
        List<Stock> list = new ArrayList<>();
        
        list.add(s);
        list.add(s.copy().setAmount(23.00));
        
        
        list.forEach(HelloWorld::printStock);
        
     }
     
     public static void printStock(Stock a){
         System.out.println(a.getId());
     }
     
     public static class Stock implements Cloneable {
         private String id;
         private String companyName;
         private Double amount;
         private Date purchaseDate;
         
         public Stock copy() throws CloneNotSupportedException{
             return (Stock) clone();
         }
         
         
         public Date getPurchaseDate(){
             return this.purchaseDate;
         }
         
         public Stock setPurchaseDate(Date d){
             this.purchaseDate = d;
             return this;
         }
         
         public String getId()   {
             return this.id;
         }
         
         public Stock setId(String id){
             this.id = id;
             return this;
         }
         
         public String getCompanyName(){
             return this.companyName;
         }
         
         public Stock setCompanyName(String name){
             this.companyName = name;
             return this;
         }
         
         public Double getAmount(){
             return this.amount;
         }
         
         public Stock setAmount(Double amount){
             this.amount = amount;
             return this;
         }
     }
}

Jukebox5

public class HelloWorld{

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

2. 前20项之和

public class Text20 { 
    //分析:抓住分子与分母的变化规律。 分子分母都是斐波那契数列,递推公式的得出较为简单
 public static void main(String[] args) { 
  float fenmu=1;float fenzi=2; 
  float sum=fenzi/fenmu; 
  float t=0; 
  for(int i=1;i<20;i++) 
  { 
   t=fenmu+fenzi; 
   fenmu=fenzi; 
   fenzi=t; 
   sum=sum+fenzi/fenmu; 
   System.out.println(sum); 
  } 
 } 
} 

SelSort

public class SelSort{
	public static void main(String[] args)
	{
		int n,i;
		n=args.length;
		int[] a=new int[n];
		for(i=0;i<n;i++)
		{
		          a[i]=Integer.parseInt(args[i]);
		}
		selectionSort(a);
		printArray(a);
	 }
        static void printArray(int[] x)
       {
	   int i,j, n=x.length;
	   for(i=0;i<n;i++)
	  	System.out.println(x[i]+ "\t");
	}
 	static void selectionSort(int[] x)
	{   
	    int i,j, temp, n;
	    n=x.length;
	    for(i=0;i<=n-2;i++)
	 	 for(j=i+1;j<=n-1;j++)
 		        if(x[i]>x[j])
		        {
		        	temp=x[i];
		        	x[i]=x[j];
			x[j]=temp;
		        }	
        }
}

Compile and Execute Java8 Online

public class HelloWorld{

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

    System.out.println("Hello World1");


    System.out.println("Amarachi is beautiful");
}    
}

Hello World

public class HelloWorld{

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

Advertisements
Loading...

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