java_cheat_sheet_2

java_cheat_sheet_2 - HP JAVA Cheat Sheet INPUT with...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
HP JAVA Cheat Sheet INPUT with JOptionPane import javax.swing.*; public class TriangleArea { public static void main(String[] args) { String baseString,heightString; double base; // base of triangle. double height; // height of the triangle double area; // area of triangle baseString = JOptionPane.showInputDialog( "Enter base:" ); heightString = JOptionPane.showInputDialog( "Enter height:" ); base = Double.parseDouble( baseString ); height = Double.parseDouble( heightString ); area = ( .5 )*base*height; // Compute the area. JOptionPane.showMessageDialog( null , "The base was " + base + "The height was " + height + "The area of the triangle is " + area); } // end of main() } // end of class TriangleArea Java Primitives/Variables Integers int= -2,147,483,648 to 2,147,483,647 Real Numbers : Double = +10 38 (15 significant figures) Single Characters: Char letter=’A’; Boolean values (true or false) Boolean isPrime= true; String Values: String name = “Erin”; Arrays (see Java Array Class): int theArray[] = new int[10]; 1 dimensional int theArray[][]=new int[6][6]; 2 dimensional Standout Output Methods System.out.print(“Enter the score”); (same line) System.out.println(“Try again”); (new line) System.out.println(“The answer is “+ 42);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/29/2010 for the course CS 5503 taught by Professor Kaylor during the Spring '10 term at W. Alabama.

Page1 / 2

java_cheat_sheet_2 - HP JAVA Cheat Sheet INPUT with...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online