CSE1310 Notes - Fundamental things that you need to know PDF

Title CSE1310 Notes - Fundamental things that you need to know
Course Introduction to Computers & Programming
Institution The University of Texas at Arlington
Pages 8
File Size 86 KB
File Type PDF
Total Downloads 96
Total Views 176

Summary

Fundamental things in CSE1310 course that you need to know...


Description

CSE1310 -Routine -Function -Method ___________ 29 AUG 2019 main args is arguments (parameters) Data types that hold Integer : short < int < long floating point : float, double Strings : not a primitive data type, it’s a built-in class. (classes starts with capitalize letters) Primitive - Integer, Floating pt, Char, Byte, Boolean Classes - String, System.out We created String variables, called Object, NOTE : Variables from class called object int value //declaration _______ int : data type , value : variables String yoyo //instantiation ______ String : class, yoyo : object Variables name in JAVA can’t start with a digit/number/special characters except “_”. int harryPotter

// this variable name style is called “CAMEL CASE”.

PUT “final” BEFORE THE VARIABLE TO MAKE IT CONSTANT ( WON’T CHANGE) In java “=“ means assign “+” : concatenate ____________3 SEPT 2019 Math : Built in class. Math.random()*100 = random number between 0-100 Scanner : Another built in class. Scanner input = new Scanner(System.in); NOTE : WE NEED “ import java.util.Scanner;” for the Scanner to work. c3po = input.nextInt(); *remember to but output message to tell ppl what to do next: read a word (read until it sees a space) nextLine: read the whole sentence

*These will continue to read things that the previous scanner stopped reading. **LINE means things you typed from the keyboard before pressing enter. *what is the difference between nextDouble and nextFloat the dot “.” named “Selector”, used to use select action (method) from classes Parenthesis “(____)” let us pass stuff into the method if required. - Called inputs, arguments, parameter. Integer is another built in class ( wrapper class-) Integer.parseInt( a String) - converting a String to a number. Space and lines matter when java reading String WRAPPER CLASS: -Integer (for int) -Double (for double) -Character ( for char) nextLine read the blank before a phrase too. ______________5 SEPT 2019 Declaration : Starts with data type ( int, String, double,…) Assignment: abc=wow; Calling methods( functions, routine): Print, Input, Parse

SEQUENTIAL CONTROL Declarations Method calls Assignments SELECTION CONTROL If Nested if else : if else in sides of other ifs else if ( {

) ACTIONS ( THIS IS CALLED COMPOUND STATEMENT)

}

_____________10 SEPT 2019 3 TYPES CONTROL STRUCTURES +SEQUENTIAL: =, method calls, declaration +SELECTION: if else +REPETITION:

__________12 SEPT 2019 LOGICAL OPERATORS: && ||

!

3 TYPES OF CONTROL IN JAVA : SEQUENTIAL: assignment, declaration, method call SELECTION: if, else if, switch REPETITION: while, for

*switch doesn’t like floating point number EX: switch ( tempRobot) { case 1976: System.out.println(“YOYO”); break; case 1977: System.out.println(“Yuh”); break; } taking advantage of the case properties switch (‘a’) { case ‘a’: case ‘A’: System.out.println(“Apple”); break; default: System.out.println(“”); } ___________15 SEPT 2019 The while loops can execute 0 time. ____________17 SEPT 2019

For (initialize; testl; inr) comma has the lowest presidential in java int c1, c2, c3 = 3, c4 =2;

System.out.println(“Counter value is “ +counter+ “ and counter is “ + ( counter %2 ==0?”even”:odd”)); => CONDITIONAL OPERATOR ( test ? trueAnswer : falseAnswer)

_________24 SEPT 2019 How to hook a file into a scanner Scanner inputFile; File inFile = new File(“document.txt”); try { inputFile = new Scanner(inFile); System.out.println(“File is found”); } // If java can’t find the file, it’ll go to the catch catch(FileNotFoundException fnfe) { inputFile = new Scanner(System.in); (make sure inputFile have a value) System.out.println(“Input file document.txt not found”); }

while (input.File.hasNext()) //checking if there is anymore datas in the file { tempName = input.File.next(); tempYear = inputFile.nextInt(); tempBMT = (inputFile.next()).charAt(0); tempTitle = inputFile.nextLine(); *Print tempName,Year,Title* } //Remember to have extra blank line at the end of the .txt

_____8 OCT 2019e public static void main(String[]args)———> method static: definition at how java look at this piece of code public static RETURN_TYPE NAME ( PARAMETERS) SIMPLIFY A FRACTION:

public static main … { int d=30; int n =12; int g = 0; g=gcf(d,n); sout } public static int gcf(int denom, int num); { int factor=0; int smaller= 0; if(denom>num) { smaller =num;} else {smaller = denom;} for (int i =2;i RECURESIVE

RECURSION = REPITION CONTROL

int[] factarray = new int[10]; factarray[k]= factk; _______________________________

OCT 17, 2019 Recursion: a method calls itself Must have a base case - case that stop the recursion JAVA automatically fill the int array with 0s ARRAY - DATA STRUCTURE THAT HOLDS MULTIPLE VALUES OF THE SAME TYPE. int [] array = new int [ 10 ] data type array notation variable name size ____________ array[2] = 12-x; Array contains many of single variables *contiguous

array in the method uses the same address of the method in the main routine

______________________

OCT 24, 2019 PASS BY VALUE int, string, char, float, double: pass by value same on the main/method)

(the variable is not the

PASS BY REFERENCE array new: int array[] = new int[5] {1,2,3,4,5}; sout(array); => it’s gonna print where array is stored (address) FINDING a in the array finding a=20 boolean found = false; int [] arr={12,30,40}; for(int = 0, i - justified to the left

ex: Marius 1920

P R.U.R

ke

Maria

1927

M Metropolis

_________

NOV 12, 2019 Star War 10000 tempTitle = inputFile.nextLine(); String [] twds = temTitle.split(); twds.length = 4 *twds[0] = “” twds[1] = “Star” twds[2]=“Wars” twds[3]=“10000” array => .length String/element => .length()

trim : delete spaces at begin and end of the String 2 dimensional array: int [] [] robotInts = new int [row] [column] String [] [] robotStrs = new String [row] [column] _________

NOV 21, 2019

Wrapper Integer Double Char

int double char

ArrayList rNumbers = new ArrayList();...


Similar Free PDFs