- 3

Please help me solve it

A client wants you to write a program that prints all numbers from 0 to the inputted number that are either a multiplier of 3 or end with 3. Sample input 14 Sample output 3 6 9 12 13 My attempt import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int x = read.nextInt(); //your code goes here while(x%3==0 || x%10==3) { System .out.println(x); x++; } } }

9th Oct 2020, 4:39 AM
muhammed sinan
muhammed sinan - avatar
9 Réponses
+ 2
Did you try to solve it? If yes then post your code else try it yourself first.
9th Oct 2020, 4:44 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
Please show ur attempt. Discuss is not for giving challenges to others. https://www.sololearn.com/discuss/1316935/?ref=app
9th Oct 2020, 4:44 AM
Steve Sajeev
Steve Sajeev - avatar
+ 2
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); int z = 0; //your code goes here while (number > z) { z ++; if (!(z % 3 == 0) && (!(z % 10 == 3))) { continue; } System.out.println(z); } } }
24th Aug 2021, 11:36 AM
Azhar Fauzi
Azhar Fauzi - avatar
+ 1
muhammed sinan , That's a Java code. Why tagging javascript then? Edit your question and add relevant tag.
9th Oct 2020, 4:47 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 1
If you want it in java then the code is correct. The only thing is that, thus code will print everything from the inputed number to 0.muhammed sinan med
9th Oct 2020, 4:50 AM
Steve Sajeev
Steve Sajeev - avatar
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); //your code goes here while( number%3==0 || number%10==3) { System .out.println(number); number--; } } }
9th Oct 2020, 4:46 AM
muhammed sinan
muhammed sinan - avatar
0
Sorry , mistaken ...
9th Oct 2020, 4:49 AM
muhammed sinan
muhammed sinan - avatar
0
But my 3 out of 4 test cases are failed .why ?
9th Oct 2020, 4:52 AM
muhammed sinan
muhammed sinan - avatar
0
while (number % 3 == 0 || number % 10 ==3) { System.out.println(number); number++;} what am i doing wrong??
14th Mar 2021, 4:30 AM
Karina Matlock
Karina Matlock - avatar