Question

In: Computer Science

Java Write a program that displays all the numbers from 100 to 200 that are divisible...

Java

Write a program that displays all the numbers from 100 to 200 that are divisible by 5 or 6, but not both

Make sure all instructions and outputs for the user are explicit

Solutions

Expert Solution

Java code:

public class Main{
public static void main(String[] args){
//printing a message to user about what this program does
System.out.println("All numbers between 100 and 200 that are divisible by 5 or 6, but not both are:");
//looping from 100 to 200
for(int i=100;i<=200;i++){
//checking if the number is divisible by 5 or 6 and not both
if((i%5==0 || i%6==0) && !(i%5==0 && i%6==0))
//printing the number
System.out.println(i);
}
   }
}


Screenshot:


Output:


Related Solutions

JAVA Write a program to sum the numbers from 1 to 100 that are divisible by...
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by 7, and compute the average of those numbers, print both the sum and the average with appropriate messages to the screen. Run the program. Capture the console output. Put the program code and console output at the end of your text file,
Write a C++ program that displays the numbers between 1000 and 9999, which are divisible by...
Write a C++ program that displays the numbers between 1000 and 9999, which are divisible by sum of the digits in them. For example, 2924 is divisible by (2+9+2+4 = 17). Your program should display all these possible numbers in the given range, and each number should be separated from the other by a space.
in java Write a program that reads in ten numbers and displays the number of distinct...
in java Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct numbers. Here is the sample run of the program: Enter...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
Write a Java program which reads a positive integer from the command line, then displays the...
Write a Java program which reads a positive integer from the command line, then displays the sum of all even values up to and including the value provided, followed by the sum of all odd values up to and including the value provided. validate that the command line argument is an integer greater than 0 to validate the type, you can use Integer.parseInt() with a try/catch for NumberFormatException use one or more for loops to perform the even and odd...
Write a Java program that creates an array with 20 random numbers between 1 and 100,...
Write a Java program that creates an array with 20 random numbers between 1 and 100, and passes the array to functions in order to print the array, print the array in reverse order, find the maximum element of the array, and find the minimum element of the array. The prototype of the methods: public static void printArray(int arr[]) public static void printArrayReverse(int arr[]) public static int searchMax(int arr[]) public static int searchMin(int arr[]) Sample output: Random Array: [17 67...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text label and a button.When the program begins, the label displays a 0. Then each time the button is clicked, the number increases its value by 1; that is each time the user clicks the button the label displays 1,2,3,4............and so on.
CS 206 Visual Programming, Netbeans Problem: Write a Java program that displays all the leap years,...
CS 206 Visual Programming, Netbeans Problem: Write a Java program that displays all the leap years, 10 per line, from 1001 to 2100, separated by exactly one space. Also display the total number of leap years in this period. Hints: you need to use a loop ( for-loop is more suitable)
● Write a program that reads words from a text file and displays all the words...
● Write a program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. Must use ArrayList. MY CODE IS INCORRECT PLEASE HELP THE TEXT FILE CONTAINS THESE WORDS IN THIS FORMAT: drunk topography microwave accession impressionist cascade payout schooner relationship reprint drunk impressionist schooner THE WORDS MUST BE PRINTED ON THE ECLIPSE CONSOLE BUT PRINTED OUT ON A TEXT FILE IN ALPHABETICAL ASCENDING ORDER...
Write an application named OddNums that displays all the odd numbers from 1 through 99. All...
Write an application named OddNums that displays all the odd numbers from 1 through 99. All ODD numbers should show all together(Should not need to scroll down), do it in 10 rows. FOR C#
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT