0

Solution Code for this question.

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 Here's my try. import java.util.Scanner; class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int n = read.nextInt(); int o = 0; while (o<n) { if (o%3 ==0 || o%10 ==3) { system.out.println(o); o++; } } } } }

21st Oct 2020, 11:51 AM
Shubham Stark
Shubham Stark - avatar
7 Réponses
+ 2
I’m a noob too well they normally want to see the actually file but this seems like a code coach problem so you only can copy the code you have
21st Oct 2020, 12:13 PM
Jennisha Smith
Jennisha Smith - avatar
+ 1
First show your attempt here bro
21st Oct 2020, 11:53 AM
Chain Sing Maravi
Chain Sing Maravi - avatar
0
Where's your attempt?
21st Oct 2020, 11:51 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Given, i am noob
21st Oct 2020, 12:00 PM
Shubham Stark
Shubham Stark - avatar
0
Error 1: You have a extra } in the code, causes brackets mismatches. Error 2: system -> System at system.out.println() Finally, you only increases o when the if statement is true. This causes infinity loop. You should put it out of the if statement so o will be increased no matter what.
21st Oct 2020, 12:13 PM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Exactly, Jennisha
21st Oct 2020, 12:14 PM
Shubham Stark
Shubham Stark - avatar
0
Still not working CarrieForle
21st Oct 2020, 12:25 PM
Shubham Stark
Shubham Stark - avatar