# Before you Start First, read the question! If the question says you must output "Number is Prime", then make sure you output just that. Don't output "True" or "Prime." Remember, you will usually get marks simply for prompting the user and inputting a value into a variable. In other words: ```java Scanner scan = new Scanner(System.in); System.out.println("Enter a value"); String s = scan.nextLine(); ``` There are marks for design and marks for code. What does that mean? - If you can see the solution requires a loop, you will get a design mark for putting in a loop - Similarly, you will get a mark for writing an if statement if that's what the solution requires Finally, don't code more than the question asks # Digit Sums Problem The digit sum of the integer 123 is 1 + 2 + 3 = 6.  The digit sum of 11 is 1 + 1 = 2. The sum of all the digits of the numbers from 1 to 10 is 46 ( 1+ 2 + 3 + … + 9 + 1 + 0) What is the sum of all the digits of the numbers from 1 to 1000? ## 1. Create a Class ```Java class Sample { Sample(){ } public static void main(String[] args) { new Sample(); } } ``` ## 2. Add method stub The heart of this problem is finding the digit sum of a number. We’re going to need a method to work this out. Add the stub of the method. Note that I’m returning a value, not printing the result directly. This makes for a more flexible method that can be chained to other methods. ```java class Sample{ Sample(){ } public int digitSum(int number){ int sum = 0; return sum; } public static void main(String[] args) { new Sample(); } } ``` ## 3. Add some tests Even though the method doesn’t do anything yet, add some tests. ```java class Sample { Sample(){  System.out.println(digitSum(123)); // Expected answer 6  System.out.println(digitSum(1)); // Expected answer 1  System.out.println(digitSum(456)); // Expected answer 15 } public int digitSum(int number){ int sum = 0; return sum; } public static void main(String[] args) { new Sample(); } } ``` ## 4. Write the code and test it Now solve the above problem 1. Fill in the code to make the digitSum method work 2. Do a for loop to work out the total of 10 digit sums (do 10 first as the answer is given in the question.  You can check if your method is working) 3. Now work out the total of 1000 digit sums. # Exercise Prime numbers often come up in the exam. This sheet will help you to work with them [[Optimize Finding Prime Numbers]] You must complete the sheet before you move on. ## Prime Factors Prime factors are factors of a number that are, themselves, prime numbers. The prime factors of 12 are 2 2 3 1. Write a program that prompts the user to enter a number and then outputs the prime factors 2. Test your program with the following data 1. 315 = 3 3 5 7 2. 98 = 2 7 7  ## Hexadecimal Numbers [Follow this link to see two methods for converting hex to denary](https://www.bbc.co.uk/bitesize/guides/zp73wmn/revision/3#:~:text=Add%20the%20hex%20value%20to%20the%20appropriate%20base%2016%20place,%2B%2013%20%3D%2045%20in%20denary.) 1. Write a program that prompts the user to enter a two digit number in hex and then outputs the number in denary 2. Test your program with the following data 1. \#2D = 45 2. \#FF = 255 3. \#10= 16 4. \#0A = 10 # More Questions %%[A Level Section B Questions](https://www.evernote.com/shard/s301/sh/d8f0ef3b-1009-c924-9ee3-57d60aa786a4/6d0774354cebaa6d6524400ef7b6a8aa) # Answers [Solving a Section B Problem Answers](https://www.evernote.com/shard/s301/sh/f2d5e6c7-e35a-b722-a9b1-ea1828d29f90/e7dc3879d6dcb47d999ef694fcb3321a) %%