Java

571 palavras 3 páginas
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

if with multiple actions (braces) if ( xCoord > 800 ) { xAddition = -5; forwards = true; //Boolean variable }

if with else if ( hungry) //hunger is Boolean variable – must be true System.out.println("Buy the cookie!" ); else System.out.println("Buy the apple!" );

if if ( (hunger + look + smell ) > 15 ) System.out.println("Buy the cookie!" ); else if (hunger + look + smell)>20 System.out.println("Buy the cake!" ); else System.out.println("Buy the apple!" );

for for (countDown=3;countDown>=0;countDown--) { System.out.println(countDown); System.out.println("and counting."); }

Java Primitives/Variables
Integers
int= -2,147,483,648 to 2,147,483,647

Real Numbers:

while while ( dollars < 1000000.00 ) { dollars = dollars*1.05; year++; }

Double = +1038 (15 significant figures)

Single Characters:
Char letter=’A’;

Boolean values (true or false)
Boolean isPrime= true;

do looping do { System.out.println(x); } while (x>10);

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

HTML for APPPLET

Standout Output Methods
System.out.print(“Enter the score”); (same line) System.out.println(“Try again”); (new line)

Relacionados

  • java
    294 palavras | 2 páginas
  • java
    868 palavras | 4 páginas
  • java
    6870 palavras | 28 páginas
  • Java
    1657 palavras | 7 páginas
  • java
    1176 palavras | 5 páginas
  • Java
    6757 palavras | 28 páginas
  • Java
    1044 palavras | 5 páginas
  • Java
    1411 palavras | 6 páginas
  • JAVA
    1268 palavras | 6 páginas
  • java
    2412 palavras | 10 páginas