Sivabudh Umpudh sivabudh

View gist:11035584
1 2 3 4 5 6 7 8 9 10
public class StudentScore {
public String id;
public int score;
/*
// Constructor
0) The name of the method has to be the same as the class name
1) Has no return type
2) Automatically called whenever you "new" a class
3) You can have multiple constructors as long as "signature" different
View gist:10087123
1 2 3 4 5 6 7 8 9 10
public class Untitled {
// int is called "return value"
// someFunction is called "method"
// return is the Java keyword which returns result
int someFunction(int n) {
if(n==0)
return 0;
else
return someFunction(n-1) + n;
}
View gist:10083802
1 2 3 4 5 6 7 8 9 10
class Untitled {
public static void main(String[] args) {
int [][] k ={
{1,2}, // first element of k
{3,4,5}, // second element of k
{8,10,12,14} // third element of k
};
System.out.println(k.length);
System.out.println(k[0].length);
System.out.println(k[1].length);
View gist:9907800
1 2 3 4 5 6 7 8 9 10
class Untitled {
public static void main(String[] args) {
int [] array = {1,5,2,-1};
// sort
for(int k = 0; k<array.length; k++){
for(int i = k; i<array.length; i++){
if(array[i]<array[k]){
int temp = array[k];
View Untitled
1 2 3 4 5 6 7 8 9 10
class Untitled {
public static void main(String[] args) {
// Static method
add2(1, 4);
// Non-static method
Untitled object = new Untitled();
object.add1(1, 4);
}
public double add1(int x, int y)
View gist:9366609
1 2 3 4 5 6 7 8 9 10
import java.util.*;
 
class Untitled {
public static void main(String[] args) {
String string = "5,6,7,8";
String[] strings = string.split(","); // this array has 4 numbers
// "for loop" first example
for(String str : strings) // for loop difference
View TriangleArea
1 2 3 4 5 6 7 8 9
import java.util.Scanner;
 
class TriangleArea {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.println("This program will help you calculate the area of a triangle.");
System.out.print("What's the height of the triangle? ");
View example
1 2 3 4 5 6 7 8 9 10
class Example {
/*
A car has the following attributes:
1) number of wheels
2) tire type
 
A car has the following behaviors:
1) it can run at a certain speed
2) it can park
*/
View gist:9202766
1 2 3 4 5 6 7 8 9 10
class MyRobo {
int x = 5;
static int y = 6;
}
class Untitled {
public static void main(String[] args) {
MyRobo robo1 = new MyRobo();
MyRobo robo2 = new MyRobo();
robo1.x += 1;
View sample
1 2 3 4 5 6 7 8 9 10
class Object2 {
int y, x, z;
Object2 () { // constructor
y = 5; x = 2; z = 1;
}
public int doAnother() {
y += 1;
return y;
}
Something went wrong with that request. Please try again.