Minggu, 17 Mei 2015



TGS PEMOGRAMAN BERORIENTASI OBJEK
Nama :elmanudin
Kls :ti 13
npm :  13312618


1.       mengurut kan angka
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication7;

import java.util.Scanner;

/**
 *
 * @author elmanudin
 */
public class JavaApplication7 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
       // public static void main(String[] args) {

    int n, c, d, swap;
    Scanner in = new Scanner(System.in);

    System.out.println("***************************************");
    System.out.println("           PROGRAM BUBLE SORT           ");
    System.out.println("*****************************************");
    System.out.println("masukan angka yang anda inginkan: ");
    n = in.nextInt();
    int array[] = new int[n];
    System.out.println("***************************************");

    System.out.println("Inputkan " + n + " Angka :");

    for (c = 0; c < n; c++)
      array[c] = in.nextInt();

    for (c = 0; c < ( n - 1 ); c++) {
      for (d = 0; d < n - c - 1; d++) {
        if (array[d] > array[d+1]) /* For descending order use < */
        {
          swap       = array[d];
          array[d]   = array[d+1];
          array[d+1] = swap;
        }
      }
    }
    System.out.println("========================================");
    System.out.println(" data sudah urutkan :");

    for (c = 0; c < n; c++)
      System.out.println(array[c]);
  }

    }


Hasil dari running


2.       menghitung nilai matrik
int[][]nil1 = {{7,8},{5,6}};

int[][]nil2 = {{3,4},{7,8}};

int[][]hsl = new int[2][2];
System.out.println("=======================================");
System.out.println("      PROGRAM PENJUMLAHAN MATRIKS      ");
System.out.println("=======================================");
System.out.println("Matrik A");

for(int i=0;i<2;i++)

{

for(int j=0;j<2;j++)

{

System.out.print(nil1[i][j]+" ");

}

System.out.println();

}
System.out.println("=======================================");
System.out.println("Matrik B");

for(int k=0;k<2;k++)

{

for(int l=0;l<2;l++)

{

System.out.print(nil2[k][l]+" ");

}

System.out.println();

}

//Proses

for(int x=0;x<2;x++)

{

for(int y=0;y<2;y++)

{

hsl[x][y]=nil1[x][y]+ nil2[x][y];

}

}

System.out.println("=======================================");
System.out.println("Hasil Penjumlahan Matriks A Dan B :");

for(int x=0;x<2;x++)
{
for(int y=0;y<2;y++)
{
System.out.print(hsl[x][y]+" " );
}
System.out.println();
  }

    }
}

Hasil running dri matrik


3.       PENJUMLAHAN DATA


package javaapplication9;
import java.util.Scanner;
/**
 *
 * @author elmanudin
 */
public class JavaApplication9 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
         int nilai; int jml=0;
    boolean stop=false;

    Scanner a=new Scanner(System.in);
    System.out.println("=====================================");
    System.out.println("         PROGRAM PENJUMLAHAN   DATA    ");
    System.out.println("=====================================");
    System.out.println("Program  data  Terus Meminta Anda Untuk");
    System.out.println("masukan, Iilain 0 Jika Ingin Berhenti");
    System.out.println("=====================================");
    for(int jumlah=0;!stop;jumlah++)
        {
        System.out.print("Inputkan Angka: ");
        nilai= a.nextInt();
        jml=jml+nilai;
        if(nilai==0) stop=true;  
        }
    System.out.println("***************************");   
    System.out.println("Jumlah Total= " +jml);
    }
}

Hasil dari running




 selamat mencoba,semoga sukses

0 komentar

Posts a comment

 
© Sukses
Designed by Blog Thiết Kế
Back to top