/DivisibleBy11.java Secret
Created
January 8, 2018 14:15
Java dilinde 11'e tam bölünebilme denetimi DivisibleBy11.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Algoritma; | |
import java.util.Scanner; | |
public class DivisibleBy11 | |
{ | |
void Divide() | |
{ | |
// http://ercanbozkurt.blogspot.com | |
Scanner sc=new Scanner(System.in); | |
System.out.print("Test edilecek sayıyı giriniz (en az 5 haneli): "); | |
int no=sc.nextInt(); | |
sc.close(); | |
int sume=0,sumo=0,diff=0; | |
String nst=Integer.toString(no); | |
int l=nst.length(); | |
if(l>=5) | |
{ | |
for(int i=0;i<l;i++) //1 | |
{ | |
int digit = Integer.parseInt(nst.charAt(i)+""); //2 | |
if(i%2==0) | |
{ | |
sume=sume+digit; //3 | |
} | |
else | |
{ | |
sumo=sumo+digit; //4 | |
} | |
} | |
if(sume>sumo) | |
{ | |
diff=sume-sumo; | |
if(diff==0 || diff % 11 ==0) //5 | |
{ | |
System.out.println(no + " sayısı 11'e tam bölünür"); | |
} | |
else | |
{ | |
System.out.println(no + " sayısı 11'e tam bölünmez"); | |
} | |
} | |
else if(sumo>sume) | |
{ | |
diff=sumo-sume; | |
if(diff==0 || diff % 11 ==0) //6 | |
{ | |
System.out.println(no + " sayısı 11'e tam bölünür"); | |
} | |
else | |
{ | |
System.out.println(no + " sayısı 11'e tam bölünmez"); | |
} | |
} | |
else if(sumo==sume) | |
{ | |
System.out.println(no + " sayısı 11'e tam bölünür"); | |
} | |
} | |
else | |
{ | |
System.out.println("Lütfen en az 5 haneli bir sayı giriniz"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment