Write a java programme named Adding Numbers.java that uses a method to sum all the integers from 10 to 20 but skipping 15 and 16. Invoke the method within the print command line to print The sum of all integers from 10 to 20 excluding 15 and 16 is 134.
package numbers;
public class Numbers {
static int sum(){
int total = 0;
for(int i=10; i<=20; i++){
if(i==15 || i==16){
continue;
}
else{
total += i;
}
}
return total;
}
public static void main(String[] args) {
System.out.println("he sum of all integers from 10 to 20 excluding 15 and 16 is: "+sum());
}
}
Comments
I appreciate your master minded in java, good job guys....keep it up!!
Leave a comment