0% found this document useful (0 votes)
46 views3 pages

Nama: Alexius Damar P NPM: 2012 4350 1067 Kelas: R.2.G

The document contains 5 Java code examples with different functions: 1. A program that takes user input for exam scores and outputs the corresponding grade. 2. A nested for loop that prints increasing numbers on new lines. 3. A program that calculates factorials of user-input numbers. 4. A program that uses nested for loops to print the absolute difference of counters on new lines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

Nama: Alexius Damar P NPM: 2012 4350 1067 Kelas: R.2.G

The document contains 5 Java code examples with different functions: 1. A program that takes user input for exam scores and outputs the corresponding grade. 2. A nested for loop that prints increasing numbers on new lines. 3. A program that calculates factorials of user-input numbers. 4. A program that uses nested for loops to print the absolute difference of counters on new lines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

NAMA

NPM :
KELAS

ALEXIUS DAMAR P

2012 4350 1067


:

R.2.G

1. 0
1
2
3
10
11
13
20
21
22
23
30
31
32
40
41
42
43

2. import javax.swing.*;
class Nilai {
public static void main(String []alexius) {
int n= 0;
for (int i = 1; i <= 2; i++) {
int nilai = Integer.parseInt(JOptionPane.showInputDialog("Masukkan nilai"));
if (nilai>=90){
n= 1;
} else
if (nilai>=80) {
n= 2;
} else
if(nilai>=60) {
n= 3;
} else
if(nilai>=50) {
n= 4;
} else

if(nilai>=40) {
n= 5;
} else
System.out.println(" Nilai yang anda masukkan salah ");
switch(n){
case 1: System.out.println('A'); break;
case 2: System.out.println('B'); break;
case 3: System.out.println('C'); break;
case 4: System.out.println('D'); break;
case 5: System.out.println('E'); break;
default:
System.out.println(" Nilai yang anda masukkan salah ");
}
}
}
}
3. public class nomer3
{
public static void main(String[]args)
{
int i;
int j;
for (i=1;i<=5;i++){
for (j=1;j<=i;j++){
System.out.print(j);
}System.out.println(" ");
}
}
}
Output :

4. import javax.swing.*;
public class nomer4
{
public static void main(String[] args) {
String faktorial = "";

System.out.println("Program Menghitung Faktorial");


System.out.println("-----------------");
do {
faktorial = JOptionPane.showInputDialog("Faktorial dari : ");
int f=Integer.parseInt(faktorial);
int fak=1;
for(int i=1;i<=f;i++)
fak *=i;
System.out.println ("Faktorialnya dari "+f+" = "+fak);
}
while (false);
}
}
OUTPUT :

5.

class nomer5
{
public static void main(String[]args)
{
int absolute,b;
for (int i = 4; i >= 0; i--)
{
for (int j = 4; j >= 0; j--)
{
b=i-j;
absolute=Math.abs(b);
System.out.print(absolute+" ");
}
System.out.println(" ");
}
}
}
OUTPUT :

You might also like