This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A Java program to demonstrate that a method | |
| // can return multiple values of same type by | |
| // returning an array | |
| class Test | |
| { | |
| // Returns an array such that first element | |
| // of array is a+b, and second element is a-b | |
| static int[] getSumAndSub(int a, int b) | |
| { | |
| int[] ans = new int[2]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| class Test { | |
| public static int[] rotate90degrees(int[] v){ | |
| int[] w = new int[2]; | |
| w[0] = v[1]; | |
| w[1] = v[0]; | |
| return w; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ArrayList<String> list = new ArrayList<String>(); | |
| list.add("one"); | |
| list.add("two"); | |
| list.add("two"); | |
| list.add("two"); | |
| list.add("two"); | |
| for(int i=0;i<list.size();i++){ | |
| if(list.get(i).equals("two")){ | |
| list.remove(i); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class ArrayListExamples { | |
| public static void main(String args[]) { | |
| // Creating an empty array list | |
| ArrayList<String> list = new ArrayList<String>(); | |
| // Adding items to arrayList | |
| list.add("Item1"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Compares two {@code int} values numerically. | |
| //The value returned is identical to what would be returned by: | |
| public static int compare(int x, int y) { | |
| return (x < y) ? -1 : ((x == y) ? 0 : 1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Program { | |
| public static void main(String[] args) { | |
| // Display common numeric types. | |
| System.out.println(Character.TYPE); | |
| System.out.println(Character.SIZE); | |
| System.out.println((int) Character.MIN_VALUE); | |
| System.out.println((int) Character.MAX_VALUE); | |
| System.out.println(Integer.TYPE); | |
| System.out.println(Integer.SIZE); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Complex { | |
| private double re, im; | |
| //public int a,b,c=null; //fault | |
| public int a,b,c; //correct | |
| public String name,value=null;//correct | |
| public Complex(double re, double im) { | |
| this.re = re; | |
| this.im = im; | |
| a = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // file name: Main.java | |
| class Complex { | |
| private double re, im; | |
| public Complex(double re, double im) { | |
| this.re = re; | |
| this.im = im; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| [ | |
| "Esc", | |
| "!\n1", | |
| "@\n2", | |
| "#\n3", | |
| "$\n4", | |
| "%\n5", | |
| "^\n6", | |
| "&\n7", |