Java 18.2 | Sololearn: Learn to code for FREE!

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

4/23/2021 1:52:47 PM

Igaman Igaman

18 Answers

New Answer

+3

Put a condition in the loop that if (i%3==0). continue

+1

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

0

Please post the question and answer

0

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

0

no digits divisible by 3

0

No in the loop you do divisibles of 3 will come

0

they shouldn't be

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

0

can you explain what was wrong?

0

Do you get the answer? Do it passed all test cases?

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

0

Do you get the answer? Do it passed all test cases? Answer this question first

0

Run for loop and add if(n%3==0) that's it hope it helps you :)!!

0

Karthik Reddy Thotamgari But what about the 0 at the last?

0

Atul i forgot abt that thanks

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"); } }

-1

-1

Why println (“0”)? why did it prevent me from writing the program? nonsense