Skip to content

Instantly share code, notes, and snippets.

@dyazincahya
Last active July 11, 2017 04:47
Show Gist options
  • Save dyazincahya/8eb97b24e30909527d0d295fb7fe111d to your computer and use it in GitHub Desktop.
Save dyazincahya/8eb97b24e30909527d0d295fb7fe111d to your computer and use it in GitHub Desktop.
Semua kodingan java per materi kuliah
/**
* Write a description of class jsx_array here.
*
* @author (Cahya Dyazin)
* @version (0.1 13/06/2017)
*/
public class jsx_array
{
public static void main (String args []){
int nilai[] = new int[3];
nilai[0]=70;
nilai[1]=80;
nilai[2]=65;
for(int i=0; i < nilai.length;i++)
System.out.println("indeks ke-"+i+" = " +nilai[i]);
}
}
/**
* Write a description of class jsx_array2D here.
*
* @author (Cahya Dyazin)
* @version (0.1 13/06/2017)
*/
public class jsx_array2D
{
public static void main(String[] args) {
// membuat isi elemen array
String [][] nama_bunga = {
{"No","Bunga"},
{"1.","Anggrek"},
{"2.","Mawar"},
{"3.","Melati"},
{"4.","Tulip"}
};
int i, j; // i = baris v, j = kolom >
for ( i=0; i<5; i++)
{
for ( j=0; j<2; j++)
{
// menampilkan isi elemen baris dan kolom
System.out.print(nama_bunga[i][j]+" ");
}
System.out.println("");
}//pindah baris
}
}
/**
* Write a description of class jsx_array_dynamic here.
*
* @author (Cahya Dyazin)
* @version (0.1 13/06/2017)
*/
import java.util.Scanner;
public class jsx_array_dynamic
{
public static void main(String args [])
{
System.out.println("Masukan jumlah array yang kamu inginkan ?");
Scanner a = new Scanner(System.in);
int total_array = a.nextInt();
System.out.println("");
System.out.println("");
String container_array[] = new String[total_array];
System.out.println("=================================================");
System.out.println("Hello, Data array yang harus kamu masukan ada "+ total_array);
System.out.println("=================================================");
for(int i=0; i<total_array; i++)
{
System.out.println("Masukan nilai untuk array ke-"+ i);
Scanner b = new Scanner(System.in);
String nilai_array = b.nextLine();
container_array[i]= nilai_array;
System.out.print(" --berhasil disimpan");
System.out.println("");
System.out.println("");
}
System.out.println("==============================================");
System.out.println("Berikut adalah data array yang telah tersimpan");
System.out.println("==============================================");
for(int j=0; j<total_array; j++)
{
int ai = j+1;
System.out.println(ai +". Nilai array ke-"+ j +" adalah "+ container_array[j]);
}
}
}
/**
* Write a description of class tugas1 here.
* Hal 16 No.4 (include fungsi IF)
*
* @author (Cahya Dyazin)
* @version (11/07/2017)
*/
import java.util.Scanner;
public class tugas1
{
public static void main( String[] cahya ){
Scanner dataIn = new Scanner(System.in);
String name = "";
String a = "cahya";
System.out.print("Tolong masukan nama kamu:");
name = dataIn.nextLine();
if (name.equals(a)){
System.out.println("Uhuk-uhuk, selamat "+name+" kamu lulus :)");
}
}
}
/**
* Write a description of class tugas2 here.
* Hal 18 No.4 (pakai fungsi pengulangan for, while, do while)
*
* @author (Cahya Dyazin)
* @version (11/07/2017)
*/
import java.util.Scanner;
public class tugas2
{
public static void main( String[] cahya ){
double nilai;
int i;
Scanner dataIn = new Scanner(System.in);
for(i=1; i<=6; i++)
{
System.out.println("Masukan nilai mahasiswa "+ i +": ");
nilai = dataIn.nextDouble();
if(nilai >= 9)
{
System.out.println("--nilai A+");
}
else if(nilai < 9 && nilai >= 8)
{
System.out.println("--nilai A");
}
else if(nilai < 8 && nilai >= 7)
{
System.out.println("--nilai B");
}
else if(nilai < 7 && nilai >= 6)
{
System.out.println("--nilai C");
}
else if(nilai < 6 && nilai >= 5)
{
System.out.println("--nilai D");
}
else
{
System.out.println("Nilai terlalu jelek, kami turut prihatin!");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment