Sintaks JAVA JCreator : Ganjil Genap

Menentukan Bilangan Ganjil dan Genap Serta Jumlahnya

/**
 * AWT Sample application
 *
 * @author 
 * @version 1.00 17/08/20
 */
class Ganjil{
    public static void main(String[] args) {
        int a;
        int b;
        int sum = 0;
        int sum1= 0;
        String bilgen = " ";
        String bilgan = " ";
        for(a=1;a<=10;a++)
        {
         if(a%2==0)
         
         {
                bilgen = bilgen +a;
                sum =sum +a;
            }
            else if(a%2==1)
         {
            bilgan = bilgan +a;
            sum1 =sum1 +a;
            
          }
          
        }
        System.out.println(bilgen + " = "+sum);
        System.out.println(bilgan + " = "+sum1);
        }
    }

HASIL :


Tidak ada komentar:

Posting Komentar