- 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++; } } }
9 Réponses
+ 2
Did you try to solve it?
If yes then post your code else try it yourself first.
+ 2
Please show ur attempt.
Discuss is not for giving challenges to others.
https://www.sololearn.com/discuss/1316935/?ref=app
+ 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);
}
}
}
+ 1
muhammed sinan ,
That's a Java code. Why tagging javascript then? Edit your question and add relevant tag.
+ 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
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--;
} } }
0
Sorry , mistaken ...
0
But my 3 out of 4 test cases are failed .why ?
0
while (number % 3 == 0 || number % 10 ==3) {
System.out.println(number);
number++;}
what am i doing wrong??