-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
57 changed files
with
1,240 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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> |
This file contains 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
This file contains 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
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; | ||
} | ||
|
||
} |
This file contains 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
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"); | ||
|
||
} | ||
} | ||
} |
This file contains 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
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."); | ||
} | ||
} | ||
} |
This file contains 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
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."); | ||
} | ||
} |
This file contains 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
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); | ||
} | ||
|
||
} | ||
} |
This file contains 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
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); | ||
} | ||
} | ||
|
||
} |
This file contains 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
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); | ||
|
||
|
||
} | ||
} |
This file contains 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
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 | ||
} |
This file contains 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
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); | ||
} | ||
|
||
} |
This file contains 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
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(); | ||
|
||
} | ||
} |
This file contains 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
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); | ||
|
||
} | ||
} |
This file contains 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
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; | ||
} | ||
} | ||
} |
This file contains 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
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"); | ||
|
||
|
||
|
||
} | ||
} |
This file contains 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
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); | ||
} | ||
} |
This file contains 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
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."); | ||
} | ||
|
||
} |
This file contains 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
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); | ||
|
||
|
||
} | ||
|
||
} |
Oops, something went wrong.