Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Answer in Java , Fully Commented Write a program that will ask the user for a po

ID: 3687945 • Letter: A

Question

Answer in Java , Fully Commented

Write a program that will ask the user for a positive integer and then display on the console whether the integer is divisible by 7 (without a remainder). For example, when you run your program, the following interaction would be appropriate:

(The green text represents the data typed by the user in the console.)

Of course, your message would be different if the user entered a number that is divisible by 7:

Your program only has to ask for one number at a time, but you should run your program several times, testing with numbers that you know are divisible by 7, and not divisible by 7.

Note: Your program should ensure that the number entered by the user is a positive number, and if not display an error message and stop. The following interaction would be appropriate:

Please enter an integer: -40
That wasn't a positive number! Goodbye!

Explanation / Answer

import java.util.*;
public class HelloWorld{
     public static void main(String []args){
        Scanner read=new Scanner(System.in);
        int no,flag=1;
        while(flag==1)
        {
        System.out.print("Please an integer: ");
        no=read.nextInt();
        if(no<0)
        {
            System.out.println("That's not a positive number. Goodbye!");
            flag=0;
        }
        else
        {
            if(no%7==0)
            System.out.println("This is divisble by 7");
            else
            System.out.println("This is not divisible by 7");
        }
        }
     }
     
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote