# Tag Archives: Method

## Java sum odd numbers

This program counts the sum of odd numbers between two given numbers. SumOdds.java import java.util.Scanner; public class SumOdds { public void run() { Scanner reader = new Scanner(System.in); 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. 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 »

## Java multplication table

This program asks for a multiplicand number and shows the multiplication table of given number. MultiplicationTable.java: import java.util.Scanner; public class MultiplicationTable { public void run() { Scanner reader = new Scanner(System.in); int multiplicand; System.out.print(“Which multiplication table would you like to see? “); multiplicand=reader.nextInt(); reader.close(); for(int i=1;i

## Java calculator

This program asks for two numbers and the mathematical operator to use on them. Calculator.java: import java.util.Scanner; public class Calculator { public void run() { Scanner numberReader=new Scanner(System.in); Scanner textReader=new Scanner(System.in); double number1, number2; String operator, result, rounding1, rounding2; System.out.print(“Enter first number: “); number1=numberReader.nextDouble(); System.out.print(“Enter second number: “); number2=numberReader.nextDouble(); System.out.print(“Operation: “); operator=textReader.nextLine(); numberReader.close(); textReader.close(); if(operator.equals(“+”))… Read More »

## Java min&max

The program asks for three numbers and prints either the biggest or the smallest of them depending which one you choose. BiggestOrSmallestNumber.java: import java.util.Scanner; public class BiggestOrSmallestNumber { public void run() { Scanner numberReader=new Scanner(System.in); Scanner textReader = new Scanner(System.in); int number1, number2, number3; String biggestSmallest; System.out.println(“Enter three numbers:”); number1=numberReader.nextInt(); number2=numberReader.nextInt(); number3=numberReader.nextInt(); System.out.print(“Do you want… Read More »