Question

In: Computer Science

Have a pretty good idea on how to solve this program, I'm just not very accustomed...

Have a pretty good idea on how to solve this program, I'm just not very accustomed to formatting well in Java for these types of problems. In java, you have full control of what's printed, I just need to get better at it, so I thought I'd post it here to receive an answer to learn from. Thanks for everything guys.

This program must use the Exclusive OR Operator ^ in java, it must also use a while loop. The way it wants to be formatted is also listed.

Write a program that uses a while loop to detect and print multiples of 19 or 23, but not both. Use the exclusive or operator as on page 93. The program should start examining integers at 100, and examine successively larger integers until 15 multiples have been detected. Correct multiples should be printed right aligned in fields that are 6 characters wide, but with only five multiples per line. The total of all correct multiples should be reported after 15 multiples have been printed.

Solutions

Expert Solution

Code - Main.java

//class Main
public class Main
{
//starting of the program
   public static void main(String[] args) {
   //variable declare
   int n=100,countMultiple = 0,countMultipleInLine=0;
   //while loop
   do{
   //using Exclusive OR Operator ^ to check for the multiple of 19 and 23
   if(((n%19 == 0)^(n%23 == 0)) == true){
   //print the multiple
   System.out.print(n+" ");
   //increment the countMultiple variable
   countMultiple++;
   //increment count of multiple in a line
   countMultipleInLine++;
   //if the countMultipleInLine is 5 then again set it to 0 and go to next line
   if(countMultipleInLine == 5){
   //go to next line
   System.out.println();
//initialize countMultipleInLine to 0 again
   countMultipleInLine = 0;
   }
   }
   //increment n
   n++;
   }while(countMultiple !=15);//exit while loop when 15 multiple are found
   }
}

Screenshots -


Related Solutions

Hi there, I just got a homework spread sheet and have no idea how to solve...
Hi there, I just got a homework spread sheet and have no idea how to solve it. can you explain it to me? I would really appriciate your help.  Here are the questions With a tiny part from the spread sheet. A) Construct a time series of the ratio of the price of the fifth contract each day to the price of the fourth contract followed through time till the fourth contract expires. Pick a starting year below 2007 and a...
I'm doing this homework on relativity and I'm not very good at it. :( I keep...
I'm doing this homework on relativity and I'm not very good at it. :( I keep getting things wrong or confused in my head. Please help me to understand this! Thank you in advance! 3. Person A is at rest with a light clock. Person B is in a car moving to the left (as seen by Person A with a light clock). Discuss how each person will perceive time. Use algebra to find the time measured by Person A...
This is just a very basic program/problem in Java I'm looking for some second opinions on....
This is just a very basic program/problem in Java I'm looking for some second opinions on. 1. Ask the user for a year input (positive integer - should be between 1500 and 2019, inclusive). 2. If the year input is not between 1500 and 2019, do not check for leap year, rather print that this year cannot be checked. 3. Take a year input from the user (should be between 1500 and 2019) 4. If the input year is a...
Okay, I have a general idea of how to use the scanner, but i'm a bit...
Okay, I have a general idea of how to use the scanner, but i'm a bit confused of how to ask multiple questions and also how maps work, which is making me struggle on this questions... If i had more time, i'd study a bit more, but I only have about 3 hours. If possible, could you explain every step with comments? Use the scanner class to ask users their name and age. Store at least 10 users on a...
hi so i'm new to c++ i understand the language pretty good however no experience whatsoever...
hi so i'm new to c++ i understand the language pretty good however no experience whatsoever with visual studio here is the assigment Examine, understand, compile and run the FruitJuice Program (all files) and submit it (a copy is made available on LMS) i know what the program does and i get what is doing but i don't even know if i'm opening the thing the right way from visual studio it wont see it as a project at all....
1. You just has a bunch on twinkies for breakfast. Initially, you feel pretty good, but...
1. You just has a bunch on twinkies for breakfast. Initially, you feel pretty good, but then feel low energy. After a few hours, you start to feel a little better. Describe what is happening to glucose regulation starting from just before before breakfast to a few hours after you eat. Be sure to mention what is happening in the pancreas, liver, muscle and adipose.   2. After consuming a high salt diet, why to both ANF and AVP go up...
I'm very confused on how to complete this code. There are 5 total classes. I have...
I'm very confused on how to complete this code. There are 5 total classes. I have some written but it isn't quite working and the Band class especially is confusing me. I posted the entire thing since the band and manager class refer to the other classes' constructors and thought it would be helpful to post those as well. Person class is a base class: Private variables String firstname, String lastname, int age Constructor has the parameters String firstname, String...
I'm pretty new to JUnit testing. Can someone demonstrate how to test one of the tree...
I'm pretty new to JUnit testing. Can someone demonstrate how to test one of the tree traversals and the add() and addrecursive() methods? public class BinaryTree { private MorseNode<Character> root = new MorseNode<Character>(); private MorseNode<Character> left = null; private MorseNode<Character> right = null; public MorseNode<Character> getRoot() { return root; } public void printPostorder(MorseNode<Character> node) { if(node == null) {return;} //System.out.print(node.getLetter()); //traverse left subtree printPostorder(node.getLeft()); //traverse right subtree printPostorder(node.getRight()); //node if(node.getLetter() != null) { System.out.print(node.getLetter() + " ");} } public void...
Nigel and Amy have been business partners for a few years. They had a pretty good...
Nigel and Amy have been business partners for a few years. They had a pretty good working relationship in the beginning, but as their business expanded they started to have more disagreements and conflicts. Finally, they had a big argument and refused to speak with each other afterwards. However, both knew that they probably still need to work together. Thus they asked a mutual good friend, Jon, to intervene and solve the conflict. Jon is a senior person in the...
Making a program in Python with the following code types. I'm very confused and would love...
Making a program in Python with the following code types. I'm very confused and would love the actual code that creates this prompt and a brief explanation. Thanks! A comment on the top line of your program containing your name. A comment on the second line containing your section number. A comment on the third line containing the date. A comment on the fourth line containing your email address. A comment with the lab number and purpose of this lab....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT