Monday, August 26th '13
Holla hoppp. ^^
Next, I want you to know about the operator.
In Java, we know 4 operators.
First is Arithmetic Operator
Consist of: +, -, *, /, and %(modulus)
I'm sure the you well know about that operator.For %(modulus), it maybe new for some people.
Modulus is the rest of the result of two number
Example:
@ 10%3=1, cause 10/3=3, and the rest is 3
@ 100%6=4, cause 10/4=2, and the rest is 2
@100%11= 1, cause 10/4=2, and the rest is 2
How to wrte the syntax? This an example:
import java.util.Scanner;
public class Hitung2
{
public static void main (String [] args)
{
int a,b,jum,kur,ba,ka,mod;
Scanner scan = new Scanner (System.in);
System.out.print("Masukkan nilai a:");
a = scan.nextInt();
System.out.print("Masukkan nilai b:");
b = scan.nextInt();
jum=a+b;
kur=a-b;
ba=a/b;
ka=a*b;
mod=a%b;
System.out.println("\nHasil Penjumlahan dua bilangan adalah:"+jum);
System.out.println("Hasil Pengurangan dua bilangan adalah:"+kur);
System.out.println("Hasil Pembagian dua bilangan adalah:"+ba);
System.out.println("Hasil Perkalian dua bilangan adalah:"+ka);
System.out.println("Hasil Modulus dua bilangan adalah:"+mod);
}
}
2.
0 komentar:
Posting Komentar