Tag Archives: If&Else

Java NumberTable

Program asks you to enter 10 numbers and lists them from biggest to smallest. After the list is shown, the program asks if you would like to check for a specific number from the list. import java.util.Scanner; public class NumberTable { Scanner numberReader=new Scanner(System.in); Scanner textReader=new Scanner(System.in); double[] numbers=new double[10]; private void run(){ getNumbers(); arrangeNumbers();… Read More »

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 »

Java calculate discount

The program asks for a price, checks if it is higher than 1000. If the price is less, it checks if it’s higher than 600 and prints the discounted price or a notification that the price wasn’t high enough. CalculateDiscount.java: import java.util.Scanner; public class CalculateDiscount { public void run() { Scanner reader=new Scanner(System.in); String over6hundred=”8%”,… Read More »