Populer Posts Hari ini
Popular Posts
-
Java Inputan / Ouput Kumpulan Source Code dengan Bahasa Java IF ...
-
#include <stdio.h> #include <conio.h> #include <stdlib.h> void main() { int musuh,player; char ulang; rand...
-
Perulangan For yaitu perulangan yang dilakukan ketika kondisi kapan perulangan dihentikan dan banyaknya proses perulang...
-
#include <stdio.h> #include <stdlib.h> void DesimalToBiner(int N){ if(N>1){ DesimalToBiner(N/2); } ...
-
1. Insertion Sort 2. Buble Sort 3. Shell Sort 4. Quick Sort 5. Pengurutan Matriks
-
Contoh Kombinasi Misalkan dalam suatu tim terdapat 4 orang alhli statistik yang sedang melakukan proyek survey. Dalam pr...
-
Apa itu Eksepsi ??? Eksepsi adalah kesalahan-kesalahan yang terjadi pada saat program sedang dijalankan atau suatu objek ya...
-
Kalkulator adalah alat bantu hitung elektronik yang banyak digunakan oleh masyarakat. untuk melakukan perhitun...
-
Faktorial dari bilangan asli n adalah hasil perkalian antara bilangan bulat positif yang kurang dari atau sama dengan...
-
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templat...
Labels
Lorem 1
adsense
Circle Gallery
News
package mengurutkanarray;
import java.util.Arrays;
public class MengurutkanArray {
public static void main(String[] args) {
// TODO code application logic here
int[] Array={5,2,8,7,1};
Arrays.sort(Array);
System.out.println(Arrays.toString(Array));
}
}
Output
array - Library java
Source Code
package CekKarakter;
public class CekKarakter {
public static void main(String[] args) {
// TODO code application logic here
String Karakter ="Hello World";
System.out.println(Karakter.startsWith("H"));
System.out.println(Karakter.endsWith("d"));
}
}
Output
java - Library java
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
public class NewJFrame extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
TanggalJamRealTime();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
Tanggal = new javax.swing.JLabel();
Jam = new javax.swing.JLabel();
TTanggal = new javax.swing.JLabel();
TJam = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(102, 255, 255));
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel1.setText(" Menampilkan Tangal dan Jam");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(36, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 361, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(3, 3, 3))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
.addContainerGap())
);
Tanggal.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
Tanggal.setText("Tanggal :");
Jam.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
Jam.setText("Jam :");
TTanggal.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
TJam.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(89, 89, 89)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(Tanggal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(Jam, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(TTanggal, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(TJam, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(66, 66, 66)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Tanggal)
.addComponent(TTanggal, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Jam)
.addComponent(TJam, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 97, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
public void TanggalJamRealTime(){
Thread p=new Thread(){
public void run(){
for(;;){
Calendar cal = new GregorianCalendar();
int hari = cal.get(Calendar.DAY_OF_MONTH);
int bulan = cal.get(Calendar.MONTH);
int tahun = cal.get(Calendar.YEAR);
TTanggal.setText(hari+"/"+(bulan+1)+"/"+tahun);
int jam = cal.get(Calendar.HOUR);
int menit = cal.get(Calendar.MINUTE);
int detik = cal.get(Calendar.SECOND);
int AM_PM = cal.get(Calendar.AM_PM);
String day_night = "";
if (AM_PM == 1)
{
day_night = "PM";
}
else
{
day_night = "AM";
}
String waktu1 = jam+":"+menit+":"+detik+""+day_night;
TJam.setText(waktu1);
try{
sleep(1000);
}catch(InterruptedException ex){
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
};
p.start();
}
// Variables declaration - do not modify
private javax.swing.JLabel Jam;
private javax.swing.JLabel TJam;
private javax.swing.JLabel TTanggal;
private javax.swing.JLabel Tanggal;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
Download File Kodingan Menampilkan Tanggal dan Jam Secara Real Time di Java
Di dalam java terdapat library java.util.Data; yang dapat kita gunakan untuk menampilkan tanggal dan waktu sekarang sintaks source codenya seperti pada dibawah.
package menampilkan.taggal.dan.jam.di.java;import java.util.Date;
/**
*
*/
public class MenampilkanTaggalDanJamDiJava {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Date Now =new Date();
System.out.println(Now);
}
java - Library java
Rumus Perkalian matriks
Misalkan matriks A (a, b, c, d) berukuran 2X2 dikalikan dengan matriks B (e, f, g, h) berukuran 2X2, sehingga rumusnya akan menjadi:
Syarat dua matriks dapat dioperasikan perkalian yaitu banyak kolom matriks pertama harus sama dengan banyak baris matriks kedua, sebagai berikut:
public class Perkalian2Matriks {public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
int A[][]= new int[2][2];
int B[][]= new int[2][2];
for(int k=0;k<2;k++){
for(int l=0;l<2;l++){
System.out.print("["+(k+1)+"]["+(l+1)+"]:");
B[k][l]=input.nextInt();
}
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
System.out.print(A[i][j]+ " ");
}
System.out.println("");
for(int k=0; k<2;k++){
for(int l=0; l<2;l++){
System.out.print(B[k][l]+" ");
}
System.out.println("");
int m=2;
int q=2;
for (int j = 0; j < q; j++) {
for (int k = 0; k < p; k++) {
//Rumus Matriks
jumlah = jumlah + A[i][k] * B[k][j];
}
C[i][j] = jumlah;
jumlah = 0;
}
for(int x=0;x<2;x++){
for(int y=0;y<2;y++){
System.out.print(C[x][y]+" ");
}
System.out.println(" ");
}
}