Tampilkan postingan dengan label java. Tampilkan semua postingan
Tampilkan postingan dengan label java. Tampilkan semua postingan

Contoh Program Sorting Java

Sorting/pengurutan adalah teknik atau cara untuk mengurutkan suatu deretan data. Teknik atau algoritma untuk melakukan pengurutan, sesungguhnya ada beberapa, salah satunya: Selection Sort. Selection Sort salah satu algoritma pengurutan yang mudah untuk dipelajari.
Konsep dasarnya yaitu : “Melakukan pencarian data terkecil/terbesar pada suatu iterasi. Kemudian data tersebut ditukar dengan data[index]. index=iterasi. Jumlah iterasi ditentukan oleh banyaknya data atau ‘N’. Iterasi=N-1.”

Contoh Program Sorting Java

 import jeliot.io.*;

public class Sorting {
    public static void main() {
    
int []a = new int [20];
int cur,x,temp,cur2,temp2;

System.out.print("Banyak Data : ");
x=Input.readInt();
    for(int i=0;ia[k]){=""  system.out.print("=""  system.out.print("]=""  system.out.print("data=""  system.out.print(a[i]);=""  system.out.print(i+1);=""  temp2="a[t];"  temp="a[i];"  }="" :="" <="" [");="" \n="" a[t]){="" div="" i="0;i


how to control program in java with switch case

in this Occasion will of course try to make with the control program uses the switch-case, and this time some earnest Also attempting to bring java programming language. how the syntax is before us to implementasika in programming languages​​:

syntax in the program control switches case are as follows:

switch () {
this case-value:
Code to execute if == this-value
break;
That case-value:
Code to execute if That-value ==
break;
...
default:
Code to execute if does not equal the value Following any of the cases
break;
}


and below is the implementation of a conversion program using the switch on the case, why menggnaka switch case because memunyai a limited extent.

import java.util.Scanner;
public class MyClass {
public static void main() {

int hari_ke;
String hari;
Scanner input = new Scanner(System.in);
System.out.print(“masukan hari_ke;”);
System.out.print(“\n”);
hari_ke = input.nextInt();
switch (hari_ke)
{
case 1 :
hari = “senin”;
break;
case 2 :
hari = “selasa”;
break;
case 3 :
hari = “rabu”;
break;
case 4 :
hari = “kamis”;
break;
case 5 :
hari = “jumat”;
break;
case 6 :
hari = “sabtu”;
break;
default:
hari = “minggu”;
break;
}
System.out.print(“hari_ke”);
System.out.print(hari_ke);
System.out.print(“adalah”);
System.out.print(hari);
System.out.print(“\n”);
return 0;
}

}


program selection by the IF ELSE in java

if in the time before we try to discuss the switch-case, on this occasion we will try, to share a little knowledge about the control program that uses the IF ELSE.

before we implement in a program we should mngetahui Else if the syntax itself, for what, because then we will be able to better distinguish between the control program if else with other control programs at a glance only, or visually.

syntax is as follows:

if (kondisi)

{

pernyataan1;



}

else

{

pernyataan2;



}


and examples of implementation of the program the opportunity this time we are attempting to program the output range of values ​​is the letter.

import java.util.Scanner;

public class MyClass {
public static void main() {

int nilai;
char nilai_huruf;
Scanner input = new Scanner(System.in);
System.out.print(“masukan nilai angka:”);
System.out.print(“\n”);
nilai = input.nextInt();
if((nilai>0)&&(nilai<=20))
nilai_huruf = ‘E’;
else if((nilai>40)&&(nilai<=60))
nilai_huruf = ‘C’;
else if((nilai>60)&&(nilai<=80))
nilai_huruf = ‘B’;
else
nilai_huruf =’A';
System.out.print(“nilai_huruf:”);
System.out.print(nilai_huruf);
return 0;
}
}


example class in java

hi pal this time we will membbuat Develop a program using java language, and time

We will try menerapkn wear class, before we implement

souerce his code we should know his syntak class in java,

on this occasion we will try to create a program to find area and volume of the circle.

syntak class in java language

public class NiceGuy {

private string name;

public NiceGuy(String name) {

system.out.println(“Instantion of NiceGuy named “ + name) ;

this.name=name;

}

public void sayHello() {

system.out.println(“Hello Object ……….…!!!“ ) ;

}

public sayHelloOutLoud() {

system.out.println(“HELLLOOOO OBJECT ORIENTED WORLD!!!”) ;

}

Public String getName() {

Return name;

}

}


and that following its example source code for the search area and volume of the circle:

import java.util.Scanner;
public class GlobalMembers
{
public static void main( String[] args )
{
Awal X = new Awal();
X.masukan();
X.proses();
X.keluaran();
}
}
public class Awal
{
public final void masukan()
{
System.out.print(“Masukkan bilangan input : “);
Scanner input = new Scanner(System.in);

System.out.print(“Masukkan nilai r : “);
r = input.nextInt();
}
public final void proses()
{
luas = (float)3.14*r*r;
volume =(float)4/3* (float)3.14*r*r*r;

}
public final void keluaran()
{
System.out.print(“Hasil keluaran untuk LUAS : “);
System.out.print(luas);
System.out.print(“Hasil keluaran untuk VOLUMe: “);
System.out.print(volume);
}
private int r;
private double luas;
private double volume;
}


Determining how to leap year and not with java

p4rtzone friend who is always in the blessed gods, the opportunity this time we will try

how to make the program determine the leap year and not a leap year, and for

selection we try using if else, nah but before we love the source code we must know what it is leap year, leap year is the year number is divisible by 4, well now easy to know tow, let us try to make it ok.

but first we define function

if (a % 4 !=0)
{
System.out.print(“Bukan Tahun Kabisat\n”);
}
else if ((a % 100==0)&&(a % 400 !=0))
{
System.out.print(“tahun Bukan kabisat\n”);
}
else
{
System.out.print(“tahun kabisat\n”);
}


after that let's try the same same kit to implement the source code below, but do not forget there are still some who Hars in repair, so that we can learn from his mistakes okok
ok friend ni complete source code,

import java.util.Scanner;
public class TahunKabisat
{
public static void main( String[] args )
{
Awal X = new Awal();
X.masukan();
X.proses();

}
}
public class Awal
{
public final void masukan()
{
System.out.print(“Masukkan bilangan input : “);
Scanner input = new Scanner(System.in);
System.out.print(“Masukkan nilai a : “);
a = input.nextInt();
}
public final void proses()
{
if (a % 4 !=0)
{
System.out.print(“Bukan Tahun Kabisat\n”);
}
else if ((a % 100==0)&&(a % 400 !=0))
{
System.out.print(“tahun Bukan kabisat\n”);
}
else
{
System.out.print(“tahun kabisat\n”);
}

}

private int a;

}


pogram prime recursively

The definition of prime numbers is nothing but the natural numbers greater than 1 and can only be divided by the number 1 and number itself. Examples of some prime numbers, among others, 2, 3, 5, 7, 11, 13 ...

Well, here I will share how to create Java applications to search for prime numbers recursively.

jeliot.io impor .*;

public class Perdana {

swasta statis int NilaiRekursif (nomor int, int index) {
if (index == 1)
return 1;
else if (angka% index == 0)
return 1 + NilaiRekursif (nomor, - index);
lain
return 0 + NilaiRekursif (nomor, - index);
}

public boolean cekBilanganPrima statis (int num) {
if (num> 1)
kembali (NilaiRekursiff (num, num) == 2);
lain
return false;
}

public static void main (String [] args) {
int num = 30;
if (cekBilanganPrima (num))
System.out.println ("Nomor Perdana");
lain
System.out.println ("Bukan Bilangan Perdana");
}

}


Twitter Delicious Facebook Digg Favorites More