0% found this document useful (0 votes)
30 views

The Bitwise Operator Performs A Bitwise Exclusive OR Operation

The document discusses various Java programming concepts including: 1. Declaring and initializing an integer array, accessing array elements, and finding the array length. 2. Using the enhanced for loop to iterate through an integer array and print each element. 3. Various string methods like equals(), equalsIgnoreCase(), charAt(), substring(), indexOf(), compareTo(), toUpperCase(), and toLowerCase(). 4. Math class methods like sqrt(), abs(), sin(), cos(), tan(), exp(), and random(). 5. TextIO class methods to get user input as different data types like int, double, boolean, char, string.

Uploaded by

Pratik Soni
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

The Bitwise Operator Performs A Bitwise Exclusive OR Operation

The document discusses various Java programming concepts including: 1. Declaring and initializing an integer array, accessing array elements, and finding the array length. 2. Using the enhanced for loop to iterate through an integer array and print each element. 3. Various string methods like equals(), equalsIgnoreCase(), charAt(), substring(), indexOf(), compareTo(), toUpperCase(), and toLowerCase(). 4. Math class methods like sqrt(), abs(), sin(), cos(), tan(), exp(), and random(). 5. TextIO class methods to get user input as different data types like int, double, boolean, char, string.

Uploaded by

Pratik Soni
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

int[] anArray; // declares an array of integers

anArray = new int[10]; // allocates memory for 10 integers

anArray[0] = 100; // initialize first element

int[] anArray = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};

System.out.println(anArray.length);

# Copy arrays:

System.arraycopy(copyFrom, 2, copyTo, 0, 7);

The bitwise ^ operator performs a bitwise exclusive OR operation.

# instanceof Compares an object to a specified type

# SWITCH

int month = 8;
String monthString;
switch (month) {
case 1: monthString = "January"; break;

# lower Case conversion:

String p1 ="pRaTik";

System.out.println(p1.toLowerCase());
# enhanced for statement

The for statement also has another form designed for iteration


through Collections and arrays This form is sometimes referred to as the enhanced
for statement, and can be used to make your loops more compact and easy to read. To
demonstrate, consider the following array, which holds the numbers 1 through 10:
int[] numbers = {1,2,3,4,5,6,7,8,9,10};

The following program, EnhancedForDemo, uses the enhanced for to loop through the


array:

class EnhancedForDemo {
public static void main(String[] args){
int[] numbers = {1,2,3,4,5,6,7,8,9,10};
for (int item : numbers) {
System.out.println("Count is: " + item);
}

System.exit(0)

Math.sqrt(x); Math.abs(x), Math.sin(x), Math.cos(x), and Math.tan(x). Math.exp(x)

Math.random()

String class defines a lot of functions

s1.equals(s2)

s1.equalsIgnoreCase(s2)

s1.charAt(N),
s1.substring(N,M), where N and M are integers, returns a value of type String. The returned
value consists of the characters in s1 in positions N, N+1,..., M-1. Note that the character in
position M is not included. The returned value is called a substring of s1.

s1.indexOf(s2) returns an integer. If s2 occurs as a substring of s1, then the returned value is
the starting position of that substring. Otherwise, the returned value is -1. You can also use
s1.indexOf(ch) to search for a particular

s1.compareTo(s2)

s1.toUpperCase()

s1.toLowerCase().

userInput = TextIO.getInt(); to input integer

# TextIO.put("The square of that number is "); ---- to print


TextIO.putln(square); ---- to print
b = TextIO.getByte(); // value read is a byte
i = TextIO.getShort(); // value read is a short
j = TextIO.getInt(); // value read is an int
k = TextIO.getLong(); // value read is a long
x = TextIO.getFloat(); // value read is a float
y = TextIO.getDouble(); // value read is a double
a = TextIO.getBoolean(); // value read is a boolean
c = TextIO.getChar(); // value read is a char
w = TextIO.getWord(); // value read is a String
s = TextIO.getln(); // value read is a String

You might also like