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

horribleJSHack

import java.nio.charset.StandardCharsets;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class HelloWorld{
    public static void main(String[] args) throws ScriptException {
	    ScriptEngineManager mgr = new ScriptEngineManager();
	    ScriptEngine jsEngine = mgr.getEngineByName("JavaScript");
	    jsEngine.eval("function getArray() {"
	            + "var hex_0d = parseInt(\"0D\", 16);" //<CR> character
	            + "var hex_09 = parseInt(\"09\", 16);" //<TAB> character
	            + "var hex_1b = parseInt(\"1B\", 16);" //<ESC> character
	            + "var hex_04 = parseInt(\"04\", 16);" //<EOT> character
	            + "var hex_84 = parseInt(\"84\", 16);" //<> character
	            + "var hex_0a = parseInt(\"0A\", 16);" //<LF> character
	            + "var hex_0e = parseInt(\"0E\", 16);" //<SO> character
	            + "var hex_0b = parseInt(\"0B\", 16);" //<VT> character
	            + "return [hex_0d, hex_09, hex_1b, hex_04, hex_04, hex_84, hex_0a, hex_0e, hex_0b];"
	            + "};");
	    String convertFuncSrc =
	         "function convertArray(type, arr) {"
	       + "  var jArr = java.lang.reflect.Array.newInstance(type, arr.length);"
	       + "  for (var i = 0; i < arr.length; i++) { "
	       + "    jArr[i] = arr[i];"
	       + "  }"
	       + "  return jArr;"
	       + "};";
	    jsEngine.eval(convertFuncSrc);
	    Object result = jsEngine.eval("convertArray(java.lang.Byte.TYPE, getArray());");
	    byte[] javaArray = (byte[])result;
	    for(byte i : javaArray) {
	        byte[] chr = new byte[1];
	        chr[0] = i;
	        System.out.println(String.format("%d : %02X : %s", i, i, new String(chr, StandardCharsets.UTF_8)));
	    }
	}
}

ConstructorDemo

/**
 * Demonstrates the creation of objets and their initializtion
 * with constructors.
 * 
 * @author Justin Yoder
 */
package ch3a;
 
import java.util.Random;
import java.math.BigInteger;
import java.net.HttpCookie;
import java.util.GregorianCalendar;

public class ConstructorDemo {
    public static void main(String [] args) {
        Random rand = new Random();
        BigInteger num = new BigInteger("737619865306315");
        HttpCookie cookie = new HttpCookie("username", "jyoder");
        GregorianCalendar today = new GregorianCalendar();
        GregorianCalendar birthday = new GregorianCalendar(1998,10,07);
    }
}

Arithmetic Demo

/*
 * Demonstrates the five basic arithmetic operators.
 *
 * @author Willy Ferreiras
 */
 
public class ArithmeticDemo{
    public static void main(String[] args){
        int x = 13;
        int y = 5;
        
        // Perform some arithmetic
        int z1 = x + y;
        int z2 = x - y;
        int z3 = x * y;
        int z4 = x / y;
        int z5 = x % y;
        
        /* This is an example of
        a multiline comment...
        The End. */
        
        System.out.println(z1);
        System.out.println(z2);
        System.out.println(z3);
        System.out.println(z4);
        System.out.println(z5);
    }
}

Hello World

public class HelloWorld {

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

Hello World

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

Empty Program

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

Empty Program

public class EmptyProgram{

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

Hello Wold

public class HelloWorld{

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

Switch-2

public class HelloWorld
{
    public static void main(String[] args)
    {
        String  day = "monday", dayName;
        int     dayNumber;
        
        switch ( day )
        {
            case "monday":
                dayNumber = 1;
                break;

            case "tuesday":
                dayNumber = 2;
                break;

            case "wednesday":
                dayNumber = 3;
                break;

            default:
                dayNumber = 0;
        }
        
        switch ( dayNumber )
        {
            case 1:
                dayName = "monday";
                break;

            case 2:
                dayName = "tuesday";
                break;

            case 3:
                dayName = "wednesday";
                break;

            default:
                dayName = "unknown";
        } 
        
        System.out.println("dayNumber=" + dayNumber + "  dayName=" + dayName);
    }
}

codechefxorquestionsept17

import java.util.Scanner;
class Main{
 
     public static void main(String []args){
Scanner in= new Scanner(System.in);
int N=in.nextInt();
int test=in.nextInt();
int c,d,day=0;
int[][] nodes= new int[N][2];
for(int i=0; i<N-1; i++)
{c=in.nextInt();
d=in.nextInt();
    nodes[d][1]=c;
}
for(int j=0; j<N; j++)
{nodes[j][0]=in.nextInt();}
     int days[]= new int[test];
         for(int k=0; k<test; k++)
         {days[k]=in.nextInt();
             
         }
         for(int y=0; y<test; y++)
    	 {for(; day<days[y]; day++)
    	 {
     {for(int k=N-1; k>=0; k--)
     {for(int l=N-1; l>k; l--)
     {if (nodes[l][1]==k)
     {nodes[k][0]=nodes[k][0]^nodes[l][0];
    	 }}
     }}
        
    	 
     }System.out.println(nodes[0][0]);
     }in.close();
}}

Advertisements
Loading...

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