Skip to content

Commit

Permalink
New source addded.
Browse files Browse the repository at this point in the history
source added.
  • Loading branch information
yrojha4ever committed Sep 3, 2015
1 parent 530dc7f commit 1e3b4fe
Show file tree
Hide file tree
Showing 57 changed files with 1,240 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
6 changes: 6 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
13 changes: 13 additions & 0 deletions src/control/Address.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package control;

public class Address {
String city, state, country;

public Address(String city, String state,
String country) {
this.city = city;
this.state = state;
this.country = country;
}

}
19 changes: 19 additions & 0 deletions src/control/BigDecimalIntTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package control;

import java.math.BigDecimal;

public class BigDecimalIntTest {
public static void main(String[] args) {
BigDecimal dec1 = new BigDecimal("25.5");
BigDecimal dec2 = BigDecimal.valueOf(25.5);
BigDecimal total = dec1.add(dec2); // dec1 + dec2;
System.out.println(total);

if (total.intValue() > 100)
System.out.println("total is greater then 100");
else {
System.out.println("Total is less then 100");

}
}
}
22 changes: 22 additions & 0 deletions src/control/Break.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package control;

public class Break {

public static void main(String[] args) {
boolean t = true;
first: {

second: {
third: {
System.out.println("Before the break.");
if (t)
break second; // break out of second block
System.out.println("This won't execute");
}
System.out.println("This won't execute");
}

System.out.println("This is after second block.");
}
}
}
21 changes: 21 additions & 0 deletions src/control/BreakLoop4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package control;

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

outer: for (int i = 0; i < 3; i++) {
System.out.print("Pass " + i + ": ");

for (int j = 0; j < 100; j++) {

if (j == 10)
break outer; // exit both loops

System.out.print(j + " ");
}
System.out.println("This will not print");
}

System.out.println("Loops complete.");
}
}
15 changes: 15 additions & 0 deletions src/control/Continue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package control;

public class Continue {

public static void main(String[] args) {

for (int i = 0; i < 10; i++) {
if (i % 2 == 0) { // remainder
continue;
}
System.out.println(i);
}

}
}
23 changes: 23 additions & 0 deletions src/control/Currency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package control;

public enum Currency {

PENNY(1), NICKLE(5), DIME(10), QUARTER(25);

private int value;

private Currency(int value) {
this.value = value;
}

public int getValue(){
return this.value;
}

public void printEnums(){
for(Currency curren: values()){
System.out.println(curren);
}
}

}
17 changes: 17 additions & 0 deletions src/control/CurrencyEnumTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package control;

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

Currency currency = Currency.DIME;

System.out.println( currency == Currency.PENNY );

int dimeValue = Currency.DIME.getValue();
System.out.println("Dime Value: "+ dimeValue);

System.out.println(dimeValue);


}
}
5 changes: 5 additions & 0 deletions src/control/Day.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package control;

public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}
17 changes: 17 additions & 0 deletions src/control/DoWhile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package control;

import java.util.Scanner;

public class DoWhile {

public static void main(String[] args) {
System.out.print("Enter any number: ");
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
do {
System.out.println("tick " + n);
n--;
} while (n > 0);
}

}
31 changes: 31 additions & 0 deletions src/control/Emp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package control;

public class Emp {
int id;
String name;
Address address;

public Emp(int id, String name, Address address) {
this.id = id;
this.name = name;
this.address = address;
}

void display() {
System.out.println(id + " " + name);
System.out.println(address.city + " " + address.state + " "
+ address.country);
}

public static void main(String[] args) {
Address address1 = new Address("Kathmandu", "Bagmati", "Nepal");
Address address2 = new Address("Pokhara", "Kaski", "Nepal");

Emp e = new Emp(111, "Sam", address1);
Emp e2 = new Emp(112, "Devid", address2);

e.display();
e2.display();

}
}
18 changes: 18 additions & 0 deletions src/control/ForEachDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package control;

public class ForEachDemo {

public static void main(String[] args) {
int nums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int sum = 0;
for (int x : nums) {
sum += x;

if (x == 5) {
break;
}
}
System.out.println("Sum is: " + sum);

}
}
36 changes: 36 additions & 0 deletions src/control/HelloConstTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package control;


public class HelloConstTest {

private final String dy = "MONDAY";

public static void main(String[] args) {
HelloConstTest obj = new HelloConstTest();
obj.printWeek(Day.MONDAY);

//TEST EQUAL
Day mnd = Day.MONDAY;
boolean isEqual = (mnd == Day.MONDAY);
System.out.println(isEqual);

boolean isEq = (obj.dy == "ABC");
boolean isEqual2 = (Day.SUNDAY == Day.MONDAY); //Error
}

public void printWeek(Day day){
System.out.println("Day is: ");
switch (day) {
case SUNDAY:
System.out.println(Day.SUNDAY);
break;
case MONDAY:
System.out.println(Day.MONDAY);
break;

default:
System.out.println("Day is not valid:");
break;
}
}
}
34 changes: 34 additions & 0 deletions src/control/MathFunc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package control;

public class MathFunc {

public static void main(String[] args) {

String s = "Java";
s = s.concat(" World");

String h = "HELLO";
int leng = h.length();
System.out.println(leng);

System.out.println(h.substring(0, 3));

System.out.println(h);

String t = "Broadway ";
System.out.println("Length of Broadway: " + t.length());

t = t.trim();
System.out.println("Length of Broadway after Trim: " + t.length());

System.out.println(t.indexOf('d'));

System.out.println("HEllo".equalsIgnoreCase("hello"));
System.out.println("HEllo".equals("hello"));

System.out.println("C:\\TEMP");



}
}
25 changes: 25 additions & 0 deletions src/control/RetOb.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package control;

//Returning an object.
class Test {
int a;
Test(int i) {
a = i;
}
Test incrByTen() {
Test temp = new Test(a + 10);
return temp;
}
}

class RetOb {
public static void main(String args[]) {
Test ob1 = new Test(2);
Test ob2;
ob2 = ob1.incrByTen();
System.out.println("ob1.a: " + ob1.a);
System.out.println("ob2.a: " + ob2.a);
ob2 = ob2.incrByTen();
System.out.println("ob2.a after second increase: " + ob2.a);
}
}
22 changes: 22 additions & 0 deletions src/control/Return.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package control;

import java.util.Arrays;

public class Return {


public static void main(String[] args) {
//This program print something..nad do thsi.
int[] a = { 6, 2, 3 };
Arrays.sort(a);
for(int a2 :a )
System.out.println(a2);

boolean t = true;
System.out.println("Before the return.");
if (t)
return; // return to caller
System.out.println("This won't execute.");
}

}
20 changes: 20 additions & 0 deletions src/control/ScannerEx.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package control;

import java.util.Scanner;

public class ScannerEx {

public static void main(String[] args) {
System.out.print("Write Something in console window: ");
Scanner sc = new Scanner(System.in);

String inputText = sc.next();//take input value
System.out.println(inputText);

int a = sc.nextInt();
System.err.println(a);


}

}
Loading

0 comments on commit 1e3b4fe

Please sign in to comment.