Tag Archives: DoWhile

Java age in days

Program ask for your birthday and current date and calculates your age in days. AgeInDays.java import java.util.Scanner; public class AgeInDays { Scanner reader=new Scanner(System.in); 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 & average

This program calculates the sum and average of given numbers. SumAndAverage.java: import java.util.Scanner; public class SumAndAverage { public void run() { Scanner reader = new Scanner(System.in); 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 »