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

import java.util.Scanner;
public class HelloWorld{
    public static void main(String[] args) {
        System.out.println("Input first number : ");
        Scanner in = new Scanner (System.in);
        int n1 = in.nextInt();
        
        System.out.println("Input second number : ");
        int n2 = in.nextInt();
        int sum = n1 + n2;
        System.out.println ("sum =" +n1+n2);
    }
}

468464416168168161681655+925+2+9

public class HelloWorld{

     public static void main(String []args){
         int age=20;
         String result=(age==50)?"isOk":"Gooooz";
        System.out.println("Hello World");
     }
}

Compile and Execute Java Online

public class HelloWorld{

     public static void main(String []args){
        int a = 3;
        int b = 4;
        int sum = 0;
        sum = a+b;
        
        
        System.out.println(a+"+"+b+"="+sum);
     }
}

using inline array in real code

public class HelloWorld{

     public static void main(String []args){
         HelloWorld o = new HelloWorld();
         o.printArray(new int[] {3,4,5,6,7});
        System.out.println("Done");
     }
     
     public void printArray(int[] arr) {
         for (int i : arr) {
             System.out.println(i);
         }
     }
}

gogogoletsgowegoatlastgoogle

public class HelloWorld{

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

Compile and Execute Java Online

public class HelloWorld{

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

Compile and Execute Java Online

public class HelloWorld{

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

Compile and Execute Java Online

class Papa{
    protected int x;
    Papa(){ x=40;}
    Papa(int y){x=y;}
}
class son extends Papa
{
    protected int x=0;
    son(){super(15);}
    son(int x){ }
         public static void main(String []args)
         {
                son s = new son();
                System.out.println(s.x+" ");
                Papa t =new son(2);
                System.out.println(t.x);
     }
}

elevator progrm in java code

import java.awt.geom.*;

public class elevator
{

    static int floor = 0, choice1, person = 0;

    public static void main(String args[])
    {

        floor = ((int) (Math.random() * 10 + 1));

        System.out.println("The elevator is now on floor " +floor);
        System.out.print("Which floor are you at now (0-10) where 0 = basement: ");
        choice1  =  Keyboard.readInt();

        if(floor == choice1)
        {
            System.out.println("Enter the elevator");
        }

        else if(floor > choice1)
        {
            ElevatorDown();
        }

        else if(floor < choice1)
        {
            ElevatorUp();
        }

        System.out.println("To which floor would you want to go (0-10) where 0 = basement");
        choice1 = Keyboard.readInt();

        if(floor > choice1)
        {
            ElevatorDown();
        }

        else if(floor < choice1)
        {
            ElevatorUp();
        }

    }

    public static void ElevatorUp()
    {
        System.out.println("The elevator is on it's way up...");

        for (person = choice1; choice1>=floor; floor++)

            System.out.println(floor);

        System.out.println("The elevator has arrived");
    }

    public static void ElevatorDown()
    {
        System.out.println("The elevator is on it's way down...");
        for (person = choice1; choice1<=floor; floor--)

            System.out.println(floor);

        System.out.println("The elevator has arrived");
    }
}

Compile and Execute Java Online

import java.sql.*;  
class OracleCon{  
public static void main(String args[]){  
try{  
//step1 load the driver class  
Class.forName("oracle.jdbc.driver.OracleDriver");  
  
//step2 create  the connection object  
Connection con=DriverManager.getConnection(  
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");  
  
//step3 create the statement object  
Statement stmt=con.createStatement();  
  
//step4 execute query  
ResultSet rs=stmt.executeQuery("select * from emp");  
while(rs.next())  
System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  
  
//step5 close the connection object  
con.close();  
  
}catch(Exception e){ System.out.println(e);}  
  
}  
}  

Advertisements
Loading...

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