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

Compile and Execute Java Online

public class ABC
{
    public void disp()
    {
        System.out.println("hello");
    }
    public static void main(String args[])
    {
        ABC obj=null;
        obj.disp();
    }
}

Compile and Execute Java Online

public class hello
{
   class Employee
   {
       int salary =400000;
       class programmer extends Employee
   }

relation.........demo....

import java.util.*;
interface operation
{
  double square(double a);
  double cube(double a);
  double sine(double a);
  double cosine(double a);


}
public class HelloWorld implements operation
{

    public double square(double a)
     {
        return Math.pow(a,2);

     }
      public double cube(double a)
     {
        return Math.pow(a,3);

     }
     public double sine(double a)
     {
       double z=Math.toRadians(a);
        return Math.sin(z);

     }
     public double cosine(double a)
     {
       double y=Math.toRadians(a);
        return Math.cos(y);

     }
public static void main(String args[])
{
    Double x;
   HelloWorld i=new HelloWorld(); 
  operation a=new HelloWorld();
  Scanner sc=new Scanner(System.in);
  //System.out.println("enter no");
 // x=sc.nextDouble();
 System.out.println("square is="+a.square(5));
 System.out.println("cube is="+a.cube(6));
System.out.println("sine is="+a.sine(45));
System.out.println("cosine is="+a.cosine(90));

    
}
}

Compile and Execute Java Online

import java.util.Scanner;
public class profile{

     public static void main(String []args){
        Scanner input = new Scanner(System.in);
        
        System.out.print("Your name: ");
        String name = input.nextLine();
        System.out.println(name);
        
        System.out.print("Your Surname: ");
        String surname = input.nextLine();
        System.out.println(surname);
        
      System.out.print("Your nickname: ");
        String nickname = input.nextLine();
        System.out.println(nickname);
        
        System.out.print("Your Age: ");
        String age = input.nextLine();
        System.out.println(age);
        
       
     }
}

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

public class HelloWorld{

     public static void main(String []args){
        System.out.println("Hello World");
             java.lang.Object
        java.util.AbstractCollection<E>
            java.util.AbstractList<E>
                java.util.ArrayList<E> 


     }
}

RateSpielmitSchleifen

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

int erlaubteVersuche = 0;
while (erlaubteVersuche < 1 || erlaubteVersuche > 8) {
  System.out.Println ("Wieviele Versuche? Zahl zwischen 1 - 8");
  erlaubteVersuche = Konsole.Read.int;
};

int zufallsZahl = (int)(Math.random() * 100) + 1; 
int versuchsZaehler = 0;

while (versuchsZaehler < erlaubteVersuche && gerateneZahl != zufallsZahl ) {
  versuchsZaehler++;
  System.out.Println("Versuch: " + versuchsZaehler);
  System.out.Println("Raten Sie mal");
  int gerateneZahl = Konsole.Read.int;
  
  if (gerateneZahl < zufallsZahl) {
      System.out.Println("Kleiner");
      }
  else if (gerateneZahl > zufallsZahl) {
    Sytstem.out.Println("Größer");
  }
  else {
        Sytstem.out.Println("<p>Glückwunsch, Sie haben die Zahl " + zufallsZahl + " korrekt erraten</p>");
      }
}

if (versuchsZaehler == erlaubteVersuche && gerateneZahl != zufallsZahl ) {
   Sytstem.out.Println("Sie haben die maximale Anzahl an Versuchen erreicht");
};

  

Compile and Execute Java Online

class Human{
   public void eat()
   {
      System.out.println("Human is eating");
   }
}
class Boy extends Human{
   public void eat(){
      System.out.println("Boy is eating");
   }
   public static void main( String args[]) {
      Boy obj = new Boy();
      obj.eat();
   }
}

Thread_Demo_example_print_numbers

public class HelloWorld{

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

Compile and Execute Java Online

abstract class shape{
abstract void draw();
 abstract int area();
}

class square extends shape{
int side;
square(int s){
side=s;
}
int area(){
return side*side;
}
void draw(){
System.out.println("square");
}
}

class circle extends shape{
int radius;
circle(int r){
radius=r;
}
int area(){
return radius*radius;
}
void draw(){
System.out.println("circle");
}
}

class rectangle extends shape{
    int n1;
    int n2;
rectangle(int l,int h){
n1=l;
n2=h;
}
int area(){
return n1*n2;
}
void draw(){
System.out.println("rectangle");
}
}

public class test{
public static void main(String args[]){
shape a=new square(4);
shape b=new rectangle(5,6);
circle c=new circle(3);
System.out.println(a.area());
System.out.println(b.area());
System.out.println(c.area());
}
}

Compile and Execute Java Online

public class HelloWorld{

    static class Player{
        String name;
        int hp;
        int atk;
        
        public Player(String name, int hp, int atk){
            this.name = name;
            this.hp = hp;
            this.atk = atk;
        }
        public void attack(Enemy enemy){
            System.out.println("Enemy Attack!");
            enemy.hp -= this.atk;
            System.out.println("Enemy hp :"+enemy.hp);
        }
        public boolean isLive(){
            if(hp <= 0){
                return false;
            }else{
                return true;
            }
        }
    }
    
    static class Enemy{
        String name;
        int hp;
        int atk;
        
        public Enemy(String name, int hp, int atk){
            this.name = name;
            this.hp = hp;
            this.atk = atk;
        }
        public void attack(Player player){
            System.out.println("Player Attack!");
            player.hp -= this.atk;
            System.out.println("Player hp :"+player.hp);
        }
        public boolean isLive(){
            if(hp <= 0){
                return false;
            }else{
                return true;
            }
        }
    }

     public static void main(String []args){
        
        Player player = new Player("gampari", 100, 12);
        Enemy enemy = new Enemy("Orc", 80, 5);
        
        while(player.isLive() && enemy.isLive()){
            player.attack(enemy);
            if(!enemy.isLive()) break;
            enemy.attack(player);
        }
        
        if(player.isLive()){
            System.out.println("player win");
        }else{
            System.out.println("enemy win");
        }
     }
}

Advertisements
Loading...

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