+ 2
I need help
Write a program that will find all numbers which are divisible by 7 but are not a multiple of 5, between 2000 and 3200 (both included). The numbers obtained should be printed in a list.
15 Answers
0
import java.util.Arrays;
public class Program
{
public static void main(String[] args) {
int count=0;
for (int i=2000;i<=3200;i++) {
if (i%5==0 || i%7!=0){
continue ;}
else{ count+=1;
}}
int[] list=new int[count] ;
int count1=-1;
for (int i=2000;i<=3200;i++) {
if (i%5==0 || i%7!=0){
continue ;}
else{ count1+=1;
list[count1]=i; }}
System.out.println (Arrays.toString (list));
}}
+ 5
import util package
Or
import java.util.ArrayList;
Create arraylist. if you don't know, read arrayList lesson..
Instead of printing add to list like
if ( i%7==0 && i%5 != 0 )
arraylist.add(i);
After loop print list by
System.out.println(arraylist);
Hope it helps..
+ 4
Your try?
+ 3
public class Program
{
public static void main(String[] args) {
for(int i=2000; i<=3200;i++){
if ((i%7==0) ^ (i%5==0)){
System.out.println (i);
}
}
}
}
+ 2
list=[]
for i in range(2000,3202):
if (i%5==0 or i%7!=0):
continue
else:
list.append(i)
print(list) #python
+ 1
Thank you
+ 1
i will try to do it python because training, if you want the code tell me
0
I want print result in a list
0
So how i can do it?
0
You're welcome...
0
How to make own logic programming
0
alright i see you liked my answer, i just did it here you go simple as that in python:
https://code.sololearn.com/cWPorlR4K6Hg/?ref=app
0
Rayan thanks bro
0
no problem
0
replying to you walid in the code i just liked:
i donknow java but there's a problem since you said "not a multiple of 5, then you don't write i%5 ==0 but i%5 != 0 because when you say i%5 == 0 it means i multiple of 5 and idk how to create a list in java so you have to create a list [ ] with nothing inside then list.append(i) then print(list) but in the java way 👍