Select Menu

Search This Blog

Populer Posts Hari ini

Popular Posts

Powered by Blogger.

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









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






-



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




-

Hasil Output


Source Code 

package menampilkan.taggal.dan.jam.di.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

Cara Download

                                               

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);
    }  
-

 

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:

perkalian matriks 2 kali 2

Syarat dua matriks dapat dioperasikan perkalian yaitu banyak kolom matriks pertama harus sama dengan banyak baris matriks kedua, sebagai berikut:

Contoh soal perkalian matriks 2 x 2:

Tentukan hasil perkalian matriks A dan B di bawah!

  \[ A = \begin{pmatrix} 3 & 4 \\ 1 & 2 \end{pmatrix} \]

  \[ B = \begin{pmatrix} 7 & 5 \\ 6 & 4 \end{pmatrix} \]

Jawab:

  \[ A \times B = \begin{pmatrix} 3 & 4 \\ 1 & 2 \end{pmatrix} \times \begin{pmatrix} 7 & 5 \\ 6 & 4 \end{pmatrix} \]

  \[ = \begin{pmatrix} 3 \cdot 7 + 4 \cdot 6 & 3 \cdot 5 + 4 \cdot 4 \\ 1 \cdot 7 + 2 \cdot 6 & 1 \cdot 5 + 2 \cdot 4 \end{pmatrix} \]

  \[ = \begin{pmatrix} 21 + 24 & 15 + 16 \\ 7 + 12 & 5 + 8 \end{pmatrix} \]

  \[ = \begin{pmatrix} 45 & 31 \\ 19 & 13 \end{pmatrix} \]

package perkalian.pkg2.matriks;

import java.util.Scanner;

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];
        int C[][]= new int[2][2];
        
        System.out.println("Masukkan matriks A");
        for (int i=0;i<2;i++){
            for (int j=0;j<2;j++){
                System.out.print("["+(i+1)+"]["+(j+1)+"]:");
                A[i][j]=input.nextInt();
            }
        }
        System.out.println("Masukkan matriks B")
                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();
            }
        }
        
        System.out.println("Matriks A");
        for(int i=0;i<2;i++){
            for(int j=0;j<2;j++){
                System.out.print(A[i][j]+ " ");
            }
            System.out.println("");
        }
        
        System.out.println("Matriks B");
        for(int k=0; k<2;k++){
            for(int l=0; l<2;l++){
                System.out.print(B[k][l]+" ");
            }
            System.out.println("");
        }
        
        //Jumlah baris dan kolom 2
        int m=2;
        int q=2;
        int p=2;
        
        int jumlah=0;
        for (int i = 0; i < m; i++) {
            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;
            }
        }
        System.out.println("Hasil perkalian Matriks A dan B");
        for(int x=0;x<2;x++){
            for(int y=0;y<2;y++){
                System.out.print(C[x][y]+" ");
            }
            System.out.println(" ");
        }
    }   
}