I need help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

30th Mar 2022, 9:42 PM
Walid
Walid - avatar
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)); }}
1st Apr 2022, 8:13 PM
A A
+ 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..
30th Mar 2022, 10:07 PM
Jayakrishna 🇮🇳
+ 4
Your try?
30th Mar 2022, 9:49 PM
Jayakrishna 🇮🇳
+ 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); } } } }
30th Mar 2022, 10:01 PM
Walid
Walid - avatar
+ 2
list=[] for i in range(2000,3202): if (i%5==0 or i%7!=0): continue else: list.append(i) print(list) #python
1st Apr 2022, 7:24 PM
A A
+ 1
Thank you
30th Mar 2022, 10:09 PM
Walid
Walid - avatar
+ 1
i will try to do it python because training, if you want the code tell me
1st Apr 2022, 9:34 PM
Rayan
Rayan - avatar
0
I want print result in a list
30th Mar 2022, 10:01 PM
Walid
Walid - avatar
0
So how i can do it?
30th Mar 2022, 10:02 PM
Walid
Walid - avatar
0
You're welcome...
30th Mar 2022, 10:09 PM
Jayakrishna 🇮🇳
0
How to make own logic programming
1st Apr 2022, 10:54 AM
Santosh Kumar
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
14th Apr 2022, 5:13 AM
Rayan
Rayan - avatar
0
Rayan thanks bro
14th Apr 2022, 5:14 AM
Walid
Walid - avatar
0
no problem
14th Apr 2022, 5:15 AM
Rayan
Rayan - avatar
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 👍
14th Apr 2022, 5:19 AM
Rayan
Rayan - avatar