Wednesday, August 17, 2016

Java anonymous inner class example using interface


package Interface;

interface Eatable {
void eat();
}

class TestAnnonymousInner1 {
public static void main(String args[]) {
/* Eatable e = new Eatable() {
public void eat() {
System.out.println("nice fruits");
}
};
e.eat();
*/
new Eatable() {
public void eat() {
System.out.println("nice fruits");
}
}.eat();
}
}

Wednesday, April 27, 2016

Write a program for Bubble Sort in java



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
public class BubbleSort {

public static void main(String[] args) {
float a[] = new float[5];
Scanner scanner = new Scanner(System.in);
System.out.println("please Enter Number : ");
float temp;
// input
for (int i = 0; i < a.length; i++) {
a[i] = scanner.nextFloat();
}
// sorting Bubble
for (int i = 0; i < a.length - 1; i++) {
for (int j = 0; j < a.length - 1 - i; j++) {
if (a[j] > a[j + 1]) {
temp = a[j + 1];
a[j + 1] = a[j];
a[j] = temp;
}
}
}
// output
System.out.println("OutPUT of this program : ");
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}

}




Converting a sentence string to a string array of words in Java


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class SentenceToWord {

public static void main(String[] args) {

String a = new String("My name is Shadhin");

String[] words = a.split("\\s+");

for (int i = 0; i < words.length; i++) {
System.out.println(words[i] + " ");
}

}

}

Frequently asked question in Android

(1)How to remove all caps Text from the button in android studio ?
ans: android:textAllCaps="false"