- 2

Please help me....

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++; } } }

11th Oct 2020, 10:31 AM
muhammed sinan
muhammed sinan - avatar
7 Respostas
0
You are starting from x=input number to infinity.. You shloud start from 0 to towards x. Use a for loop(to be clear and not to confuse), from i=0 to x, do i%3==0 || i%10==3... Until i<x Edit : muhammed sinan in your code, if your input is 10 then output is : 12 13 15 18 .... .... (infinite loop)...
11th Oct 2020, 10:45 AM
Jayakrishna 🇮🇳
0
Use another variable to set while condition to it or use for loop as up Jayakrishna🇮🇳 mentioned.
11th Oct 2020, 12:25 PM
HBhZ_C
HBhZ_C - 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 int count =1; while(count<=number){ if((count%3)==0||(count%10)==3){ System.out.println(count); } count++; } } } or you can use if statement regarding your answer, muhammed sinan
20th Jan 2021, 7:14 PM
VenBeta
VenBeta - avatar
0
this way you can do that import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); int i = 1; //your code goes here while(i<=number){ if (i%3==0|| i%10==3){ System.out.println(i); } i++; } } }
27th May 2021, 5:12 PM
Abhishek Biswas
Abhishek Biswas - 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(); 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
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); int f = 1; //please Subscribe to My Channel //name: Fazal Tuts4U while(f <= number) { if(f%3==0 || f%10==3) { System.out.println(f); } f++; } } }
2nd Sep 2021, 5:07 PM
Fazal Haroon
Fazal Haroon - 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 int count=1; while(count<=number){ if((count%10==3)||(count%3==0)){ System.out.println(count); } count++; } } } **This is correct answer
4th Nov 2021, 5:38 AM
Pubudu Ishan Wickrama Arachchi
Pubudu Ishan Wickrama Arachchi - avatar