Java check phone number

Program asks for a phone number and checks if it is valid. import java.util.Scanner; public class CheckPhoneNo { boolean go=true; private void run() { Scanner reader=new Scanner(; String phoneNo; while(go) { System.out.println(“Enter a phone number (6-15 numbers, may include an area code and spaces)”); phoneNo = reader.nextLine(); String phoneNoWithoutSpaces=removeSpaces(phoneNo); checkPhoneNo(phoneNoWithoutSpaces); } reader.close(); } private… Read More »

Java dice game

The program asks how much money you want to bet (amount of rounds) and throws three dice. If you get six once you win 1 euro, if twice 20 euros and if all three dice give a six you win 40 euros. import java.util.Scanner; import java.util.Random; public class DiceGame { Scanner reader=new Scanner(; Random… Read More »

Java age in days

Program ask for your birthday and current date and calculates your age in days. import java.util.Scanner; public class AgeInDays { Scanner reader=new Scanner(; int yearOfBirth, monthOfBirth, dayOfBirth, currentYear, currentMonth, currentDay, input;//Scope private void run() { yearOfBirth=getYear(“year of birth”); monthOfBirth=getMonth(“month of birth”); dayOfBirth=getDay(“day of birth”); currentYear=getYear(“current year”); currentMonth=getMonth(“current month”); currentDay=getDay(“current day”); reader.close(); int ageInDays=countAge(currentYear, yearOfBirth,… Read More »

Java sum odd numbers

This program counts the sum of odd numbers between two given numbers. import java.util.Scanner; public class SumOdds { public void run() { Scanner reader = new Scanner(; int lowLimit, upLimit, even, sum=0; System.out.println(“Enter lower and upper limit. The sum of odd numbers will be counted between the limits.”); lowLimit=reader.nextInt(); upLimit=reader.nextInt(); reader.close(); //swap places without… Read More »

Java sum & average

This program calculates the sum and average of given numbers. import java.util.Scanner; public class SumAndAverage { public void run() { Scanner reader = new Scanner(; int sum=0, newNumber=0, amount=0; double average; System.out.print(“Enter numbers. They will be summed together,\nuntil you enter the numbers between 200 and 209. “); do { amount++; newNumber=reader.nextInt(); sum=sum+newNumber; } while(newNumber209);… Read More »