Posts

Showing posts from March, 2017

Determine Two Numbers which is the largest or Both Numbers are Equal in Java

Image
In this Java program, the application will determine two input numbers which is the largest, or both the numbers input are equal. This is the same solution of  Deitel & Deitel   exercise  2.17 in Chapter 2. Write an application that ask the user to enter two integers, obtains the two numbers of the user and display the larger number followed by the words "is larger" in an information message dialog. If the number are equal, print the message "These numbers are equal". public class LargerOrEqual { public static void main(String args[]){ //Declare varables String fNumber, sNumber, result; int numb1, numb2; //Read the user inputs fNumber = JOptionPane.showInputDialog("Enter first number: "); sNumber = JOptionPane.showInputDialog("Enter second number: "); //Conver input string to integer values numb1 = Integer.parseInt(fNumber); numb2 = Integer.parseInt(sNumber); result = ""; if (numb1 > numb2) result = numb...

Calculates the Squares and Cubes in Java

Image
In this Java program, the application will display in a table the value of the squares and cubes from 1 to 10. This is the same solution of  Deitel & Deitel  exercises 2.33 in Chapter 2.  Write an application that calculates the squares and cubes of the numbers from 1 to 10 and prints the resulting values in table. public class SquareCube{ public static void main (String args[]){ //Declare the variables int square, cube, number= 1; //Dispay the header f the table System.out.printf("Number\tSquare\tCube\n"); //Loop value ntil reached no.10; while (number <= 10){ square = number * number; cube = square * number; number ++; System.out.printf(" %d\t \t%d\t \t%d\n", number, square, cube); } System.exit(0); } } Here is the output.

Simple Addition Program in Java

Image
In this Java program, the user is prompt to input two integer numbers and displays the sum in Graphical User interface (GUI). Problem: Write and applicaton the will display the sum, inputs by the user in Graphical User Interface(GUI).

Program in Java that Display the Largest & Smallest Number

Image
In this Java program, we will take 5 input numbers by the user and display the Largest and Smallest numbers in Graphical User interface (GUI). This is the same solution of Deitel & Deitel exercises 2.2. However we enhance the output and display in a GUI instead of command line: Write an application that reads five integers and determines and prints the largest and the smallest integers in the group.

Calculate the Sum, Product, Difference & Quotient in Java

Image
In this Java program, we will calculate the user inputs by Addition, multiplication, subtraction & division. The output will be displayed in Graphical User interface (GUI).  This is the solution of Deitel & Deitel exercises 2.16: Write an application that asks the user to enter two numbers from the users and prints the sum, product, difference and quotient (division) of the numbers.