Tips for heathy life

Tips for heathy life

Jumat, 31 Oktober 2008

Selection Operator 1 in Java

String status = "";
int grade = 80;
//mendapatkan status pelajar
status = (grade >= 60)?"Passed":"Fail";
//print status
System.out.println( status );

Logical NOT Operator in Java

boolean val1 = true;
boolean val2 = false;
System.out.println(!val1);
System.out.println(!val2);

Relation Operator

I want to share about relation operator. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

----------------
int i = 37;
int j = 42;
int k = 42;
System.out.println("Nilai variabel...");
System.out.println(" i = " + i);
System.out.println(" j = " + j);
System.out.println(" k = " + k);
//lebih besar dari
System.out.println("Lebih besar dari...");
System.out.println(" i > j = " + (i > j)); //false
System.out.println(" j > i = " + (j > i)); //true
System.out.println(" k > j = " + (k > j)); //false
//lebih besar atau sama dengan
System.out.println("Lebih besar dari atau sama dengan...");
System.out.println(" i >= j = " + (i >= j)); //false
System.out.println(" j >= i = " + (j >= i)); //true
System.out.println(" k >= j = " + (k >= j)); //true
//lebih kecil dari
System.out.println("Lebih kecil dari...");
System.out.println(" i < j = " + (i < j)); //true
System.out.println(" j < i = " + (j < i)); //false
System.out.println(" k < j = " + (k < j)); //false
//lebih kecil atau sama dengan
System.out.println("Lebih kecil dari atau sama dengan...");
System.out.println(" i <= j = " + (i <= j)); //true
System.out.println(" j <= i = " + (j <= i)); //false
System.out.println(" k <= j = " + (k <= j)); //true
//sama dengan
System.out.println("Sama dengan...");
System.out.println(" i == j = " + (i == j)); //false
System.out.println(" k == j = " + (k == j)); //true
//tidak sama dengan
System.out.println("Tidak sama dengan...");
System.out.println(" i != j = " + (i != j)); //true
System.out.println(" k != j = " + (k != j)); //false

VERIFIED PASSWORD and USER NAME in Java SE

String user="";
String pwd="";
user = JOptionPane.showInputDialog("Masukkan username anda : ");
pwd = JOptionPane.showInputDialog("Masukkan password anda: ");
String msg = "Welcome to java programming language, " + user + " !";
String msg2 = " Verfikasi password anda: " + "password anda = "+pwd;
JOptionPane.showMessageDialog(null, msg);
JOptionPane.showMessageDialog(null, msg2);

Kamis, 30 Oktober 2008

Find for the last word from JOPTIONPANE version in J2SE



I want to share how to Find for the last word from JOPTIONPANE version. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.


import javax.swing.JOptionPane;



public class Main {


public Main() {
}


public static void main(String[] args) {

String world1= "";
String world2= "";
String world3= "";
world1=JOptionPane.showInputDialog("Enter world 1");
world2=JOptionPane.showInputDialog("Enter world 2");
world3=JOptionPane.showInputDialog("Enter world 3");
String msg= world1 +" "+ world2 +" " + world3;
JOptionPane.showMessageDialog(null,msg);
}

}

Find for the last word from BUFFEREDREADER version in J2SE



I want to share how to Find for the last word from BUFFEREDREADER version in J2SE. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JOptionPane;

public class GetInputFromKeyboard {

public static void main(String[] args) throws IOException {
BufferedReader dataIn = new BufferedReader(new InputStreamReader (System.in));

String word1 = "",word2 ="", word3="";

System.out.println("Enter Word 1 : ");
word1=dataIn.readLine();
System.out.println("Enter Word 2 : ");
word2=dataIn.readLine();
System.out.println("Enter Word3 : ");
word3=dataIn.readLine();
System.out.println(word1 +" "+ word2+" "+ word3);


}

}

Average FIGURE FROM THREE in J2SE



I want to share how to Average FIGURE FROM THREE in J2SE. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

int number1 = 10;
int number2 = 20;
int number3 = 45;
int rata;
rata = ( number1+number2+number3)/3;
System.out.println("Rata-rata = " + rata );

Recognized and print variable



I want to share how to Recognized and print variable. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

int number = 10;
char letter ='a';
boolean result = true;
String str =" hello ";
System.out.println("Number = " + number );
System.out.println("Letter = " + letter );
System.out.println("Result = " + result);
System.out.println("Str = " + str );

Delete characters WHITESPACE AND FROM THE FINAL any string in J2SE



I want to share how to Delete characters WHITESPACE AND FROM THE FINAL any string. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

String str1=" Hello ";
String str2=" Java ";
System.out.println("Tanpa Trim : " + str1 + str2);
System.out.println("Dengan Trim : " + str1.trim() + str2.trim());

FIND OF POSITION any string in the string OTHER in J2SE



I want to share how to FIND OF POSITION any string in the string OTHER. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

String str1="Hello Java Hello Java Hello Java";
System.out.println(str1.indexOf("Java")); //6
System.out.println(str1.indexOf("Java",10)); //17
System.out.println(str1.lastIndexOf("Hello")); //22
System.out.println(str1.lastIndexOf("Hello",10)); //0