0

Java 18.2

Show me solution to the problem please Write a program that takes a number N as input and outputs numbers from N to 0, skipping multiples of 3. Sample input 7 Result example 7 5 4 2 1 0

23rd Apr 2021, 1:52 PM
Igaman Igaman
Igaman Igaman - avatar
19 Respostas
+ 3
Put a condition in the loop that if (i%3==0). continue
23rd Apr 2021, 2:56 PM
Atul [Inactive]
0
they shouldn't be
23rd Apr 2021, 3:04 PM
Igaman Igaman
Igaman Igaman - avatar
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int N = read.nextInt(); for(int i = N; i >= 0; i--){ if(i%3==0) continue; System.out.println(i); } }} //Check this
23rd Apr 2021, 3:47 PM
Atul [Inactive]
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int N = read.nextInt(); for(int i = N; i >= 0; i--){ if(i%3==0) continue; System.out.println(i); } System.out.println("0"); }} //Check this
23rd Apr 2021, 4:16 PM
Atul [Inactive]
0
can you explain what was wrong?
23rd Apr 2021, 4:21 PM
Igaman Igaman
Igaman Igaman - avatar
0
Do you get the answer? Do it passed all test cases?
23rd Apr 2021, 4:30 PM
Atul [Inactive]
0
Because in expected output 0 is present and remainder of any number with 0 is 0 So the if condition will continue that one
23rd Apr 2021, 5:46 PM
Atul [Inactive]
0
Do you get the answer? Do it passed all test cases? Answer this question first
23rd Apr 2021, 5:46 PM
Atul [Inactive]
0
Run for loop and add if(n%3==0) that's it hope it helps you :)!!
24th Apr 2021, 1:34 PM
kreddyt
kreddyt - avatar
0
Karthik Reddy Thotamgari But what about the 0 at the last?
24th Apr 2021, 2:23 PM
Atul [Inactive]
0
Atul i forgot abt that thanks
24th Apr 2021, 2:44 PM
kreddyt
kreddyt - avatar
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int number; do { //take input and output corresponding message /* 1 => Language selection 2 => Customer support 3 => Check the balance 4 => Check loan balance 0 => Exit */ number=scanner.nextInt() ; if(number==1) { System.out.println("Language selection"); } else if(number==2) { System.out.println("Customer support"); } else if(number==3) { System.out.println("Check the balance"); } else if(number==4) { System.out.println("Check loan balance"); } else break; } while(number != 0); System.out.println("Exit"); } }
31st May 2021, 2:48 PM
Monik
0
i've missed a case when i gave the response in 2021 and completely forgot abt that. just now saw this question again so answered, hope this helps :) public class Main { public static void main(String[] args) { int n = 7; call(n); } public static void call(int n){ if(n == 0){ System.out.println(n); return; } if (n%3!=0){ System.out.println(n); } call(n-1); } }
7th May 2023, 4:20 AM
kreddyt
kreddyt - avatar
- 1
Please post the question and answer
23rd Apr 2021, 2:02 PM
Atul [Inactive]
- 1
My code import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int N = read.nextInt(); for(int i = N; i >= 0; i--){ System.out.println(i); } }
23rd Apr 2021, 2:04 PM
Igaman Igaman
Igaman Igaman - avatar
- 1
no digits divisible by 3
23rd Apr 2021, 3:01 PM
Igaman Igaman
Igaman Igaman - avatar
- 1
No in the loop you do divisibles of 3 will come
23rd Apr 2021, 3:03 PM
Atul [Inactive]
- 1
Wrong
23rd Apr 2021, 3:53 PM
Igaman Igaman
Igaman Igaman - avatar
- 1
Why println (ā€œ0ā€)? why did it prevent me from writing the program? nonsense
23rd Apr 2021, 4:54 PM
Igaman Igaman
Igaman Igaman - avatar