Computer Science, asked by arkamitra01, 1 month ago

WAP in java to check the divisibility of number by 3 or not

Answers

Answered by atrs7391
3

import java.util.Scanner;

public class Main {

  public static void main(String args[]) {

     Scanner sc = new Scanner(System.in);

     System.out.println("Enter a number : ");

     int num = sc.nextInt();

     if(num%3 == 0) {

          System.out.println("Divisible");

     }

    else {

           System.out.println("Not Divisible")

     }

  }

}

Answered by shailjad731
0

Answer:

import java.util.Scanner;

public class DivisibleBy3 {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter a number :");

String num = sc.nextLine();

int digitSum = 0;

for(int i = 0; i<num.length(); i++) {

digitSum = digitSum + num.charAt(i)-'0';

}

if(digitSum % 3 == 0) {

System.out.println("Given number is divisible by 3");

} else {

System.out.println("Given number is not divisible by 3");

}

}

}

plz mark me as brainliest!!!

Similar questions