0% found this document useful (0 votes)
43 views2 pages

Cheat 111

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 2

{\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf400 {\fonttbl\f0\fnil\fcharset0 Monaco;} {\colortbl;\red255\green255\blue255;\red63\green127\blue95;} \margl1440\margr1440\vieww10800\viewh8400\viewkind0 \deftab720 \pard\pardeftab720 \f0\fs28 \cf2 /* import java.util.Scanner; import java.util.

Random;\cf0 \ \cf2 class \ul App\ulnone \{\cf0 \ \pard\pardeftab720 \cf2 \ul \ulc2 int\ulnone bird = 4;\cf0 \ \pard\pardeftab720 \cf2 private/public (final) static \ul int\ulnone pork = 9; // must initialize with final\cf0 \ \cf2 // attributes declared here\cf0 \ \cf2 // constructor below\cf0 \ \cf2 \ul App\ulnone (\ul int\ulnone pigeon) \{bird = pigeon;\}\cf0 \ \cf2 //method comes after constructor\cf0 \ \cf2 returnType methodName( varType1 var1, ..., varTypeK varK )\cf0 \ \cf2 \{\cf0 \ \cf2 // Java statements here\cf0 \ \cf2 return varWithMatchingtype;\cf0 \ \cf2 \}\cf0 \ \ \cf2 public returnType getAttribute()\{ return attribute; \} //\ul accessor\cf0 \ulnone \ \cf2 public void setAttribute(returnType x)\{attribute = x;\} //mutator\cf0 \ \cf2 // public class TestClassName\cf0 \ \cf2 public static void main( String[] \ul args\ulnone )\{\cf0 \ \cf2 Scanner input = new Scanner(System.in);\cf0 \ \cf2 String line = input.nextLine(); // waits for user to type in something\c f0 \ \cf2 \ul int\ulnone number = input.nextInt(); // waits for user to input an integer\cf0 \ \cf2 \cf0 \ \cf2 String a = "Dragon";\cf0 \ \cf2 System.out.println(a.substring(0,3)); //output: \ul Dra\cf0 \ulnone \ \cf2 System.out.println(a.substring(3)); //output: \ul gon\cf0 \ulnone \ \cf2 System.out.println(a.replace('D','n')); //output: \ul nragon\ulnone (th is is case sensitive)\cf0 \ \cf2 System.out.println(a.toUpperCase()); //output: DRAGON \cf0 \ \cf2 System.out.println(a.toLowerCase()); //output: dragon\cf0 \ \cf2 System.out.println(a.charAt(2)); //output: a\cf0 \ \cf2 System.out.println(a.length()); //outputs: 6\cf0 \ \cf2 char topG = '$';\cf0 \ \cf2 \cf0 \ \cf2 \ul int\ulnone [] \ul bucky\ulnone = new \ul int\ulnone [3]; // 3 elem ents\cf0 \ \cf2 \ul int\ulnone \ul bucky\ulnone [] = \{2,3,34\}; //creates an array\cf0 \ \cf2 \cf0 \ \cf2 System.out.println("Index\\tValue"); // outputs: Index Value\cf0 \ \cf2 \ul int\ulnone [][] \ul marray\ulnone = \{\{2,3\},\{45,99\}\}; // 2 x 2 array\cf0 \ \cf2 \ul int\ulnone [][] array = \{\{2,3\},\{45\},\{99,0,354\}\}; // 3 rows, 3 columns\cf0 \ \cf2 String[] fruits = \{\}\cf0 \ \cf2 System.out.println(\ul marray\ulnone [1][0]); // outputs 45\cf0 \ \cf2 \ul int\ulnone i;\cf0 \ \cf2 for (i = 0; i < 10; i++)\cf0 \

\cf2 if (i % 6 == 0)\cf0 \ \cf2 break; // Reserved word that breaks out of the immediat e enclosing loop \cf0 \ \cf2 \ul int\ulnone y = i;\cf0 \ \cf2 System.out.println(y);\cf0 \ \cf2 \cf0 \ \cf2 \ul int\ulnone [][] grid = \{\{3,5,488\},\{2,4\},\{1,2,3,4\}\};\cf0 \ \cf2 \cf0 \ \cf2 for (\ul int\ulnone row = 0; row <grid.length; row++) \{\cf0 \ \cf2 for (\ul int\ulnone \ul col\ulnone = 0; \ul col\ulnone < grid[row].length; \ul col\ulnone ++) \{\cf0 \ \cf2 System.out.print(grid[row][\ul col\ulnone ] + "\ \t");\cf0 \ \cf2 \}\cf0 \ \cf2 System.out.println("");\cf0 \ \cf2 \} \cf0 \ \cf2 for (row = 1; row <= 10; row++) \{\cf0 \ \cf2 for (column = 1; column <= row; column++) \{\cf0 \ \cf2 System.out.print("*");\cf0 \ \cf2 System.out.println();\cf0 \ \cf2 \}\cf0 \ \cf2 \} \cf0 \ \cf2 \cf0 \ \cf2 for (row = 10; row >= 1; row--) \{\cf0 \ \cf2 for (column = 1; column <= row; column++)\cf0 \ \cf2 System.out.print("*");\cf0 \ \ \cf2 System.out.println();\cf0 \ \cf2 \}\cf0 \ \cf2 for (row = 10; row >= 1; row--) \{\cf0 \ \cf2 for (space = 10; space > row; space--)\cf0 \ \cf2 System.out.print(" ");\cf0 \ \ \cf2 for (column = 1; column <= row; column++)\cf0 \ \cf2 System.out.print("*");\cf0 \ \ \cf2 System.out.println();\cf0 \ \cf2 \}\cf0 \ \cf2 for (row = 10; row >= 1; row--) \{\cf0 \ \ \cf2 for (space = 1; space < row; space++)\cf0 \ \cf2 System.out.print(" ");\cf0 \ \ \cf2 for (column = 10; column >= row; column--)\cf0 \ \cf2 System.out.print("*");\cf0 \ \ \cf2 System.out.println();\cf0 \ \cf2 \}\cf0 \ \cf2 if ((total < (max + 5)) && !found) // becomes (7 < (10+5)) && !t rue; && is AND, || is OR, ! is NOT\cf0 \ \cf2 \cf0 \ \cf2 */}

You might also like