Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java Programming Assignments: Comparing and Adding Numbers, Assignments of Computer Science

The source code for three java applications developed for a csci 2350 course. The first application, compare.java, asks the user to input two numbers and displays which number is larger or if they are equal. The second application, addition.java, asks the user to input two numbers and displays their sum. The third application, dialogs.java, shows different message dialog boxes with various icons. These applications can be used for learning java programming and developing simple applications.

Typology: Assignments

Pre 2010

Uploaded on 08/03/2009

koofers-user-sca
koofers-user-sca 🇺🇸

10 documents

1 / 3

Toggle sidebar

Related documents


Partial preview of the text

Download Java Programming Assignments: Comparing and Adding Numbers and more Assignments Computer Science in PDF only on Docsity! // Name: // Compare.java // Date: // CSCI 2350 // Write an application to ask user to enter two numbers, display // - the larger number + "is larger" or "These numbers are equal" // import javax.swing.JOptionPane; public class Compare { public static void main( String args[]) { int num1, num2, sum; String numStr1, numStr2, sumStr; //Read Data -- Stored as strings numStr1 = JOptionPane.showInputDialog("Enter first number. "); numStr2 = JOptionPane.showInputDialog("Enter second number. "); //Convert into integers num1 = Integer.parseInt(numStr1); num2 = Integer.parseInt(numStr2); //Create a message displaying the larger number or an equal message sumStr = ""; if (num1 > num2) sumStr = sumStr + num1 + " is larger. "; else if (num1 < num2) sumStr = sumStr + num2 + " is larger. "; else sumStr = sumStr + "These numbers are equal"; //Display in Window JOptionPane.showMessageDialog(null, sumStr); //Using Default for title and icon //Display on Command Window System.out.println(sumStr); //Exit System.exit(0); } } // Name // Addition.java // Date: // CSCI 2350 // Write an application to ask user to enter two numbers and show sum import javax.swing.JOptionPane; public class Addition { public static void main( String args[]) { int num1, num2, sum; String numStr1, numStr2, sumStr; numStr1 = JOptionPane.showInputDialog("Enter first number. "); numStr2 = JOptionPane.showInputDialog("Enter second number. "); num1 = Integer.parseInt(numStr1); num2 = Integer.parseInt(numStr2); sum = num1 + num2; //Calculate Equation sumStr = ""+ num1 + " + " + num2 + " = " + sum; JOptionPane.showMessageDialog(null, sumStr); //Using Default for title and icon //Exit System.exit(0); } } If no Icon is specified, the default is information icon.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved