Coding Flashcards

(52 cards)

1
Q

Import

A

import javax.swing.*;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Class

A

public class ________
{
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Main Method

A

public static void main (String [] args)
{
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Print

A

System.out.println(____);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Allows the user to input string

A

String ____ = JOptionPane.showInputDialog(“_____”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Variable WORDS

A

String _____ = “____”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Variable INTEGER

A

int ______ = _______;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Allows users to input integer

A

int ____ = Integer.parseInt (JOptionPane.showInputDialog (“________”));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Variable REAL NUMBER

A

double _______ = _______;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Allows users to input real number

A

double ______ = Double.parseDouble(JOptionPane.showInputDialog(“_____”));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Addition

A

+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Subtraction

A

-

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Multiplication

A

*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Division

A

/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

String -> int

A

String a = “______”;
int i = Integer.parseInt(a);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

int -> double

A

int i = ____;
double d = i;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

char -> int (ASCII value)

A

char c = ‘___’;
int i = (int)(c);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

int -> String

A

int i = ___;
String num = i + “”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

String -> char

A

String name = “___”;
char c = name.charAt(___);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

char -> double

A

char r = ‘___’;
int i = (int) (r);
double d = i;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Give char value for what the user inputs

A

char ____ = JOptionPane.showInputDialog(“___”).charAt(__);

22
Q

Prints specific letters from words in char

A

System.out.println(___.charAt(___));

23
Q

If statement numbers & true and false

A

if (ask == true)
{

}
If (ask == false)
{

}

24
Q

Boolean

A

boolean ask = Boolean.parseBoolean(JOptionPane.showInputDialog(“_______”));

25
Incrementing
num++;
26
Decrementing
num- -;
27
Modulus number
int/double num = ______.parse____(JOptionPane.showInputDialog(“Enter a number”)); if (num%2 == 0) { ______ } if (num%2 == 1) { _____ }
28
Print char for whole word
System.out.println(word.substring(__,__));
29
if statement words
if (_____.equals(_____)) { _____ } if (_____.equals(____)) { ____ }
30
if statement words (ignore case)
if (____.equalsIgnoreCase(____)) { } else { }
31
Find the length of a word
int len = ____.length();
32
Find the last letter of the word
char lastlet = ____.charAt(len-1);
33
Stop the programme
System.exit(0);
34
Print f to display columns
System.out.printf(“%-30s%-30s%-30s\n” , “______”, “______”, “______” ); - (start from LHS) + (start from RHS) 30s (the number of spaces you need)
35
char to String (not wanting to add ASCII values, but just join letters)
String a = JOptionPane.showInputDialog(“Enter a word”); char firstlet = a.charrAt(0); int asciiplus1 = (int)(firstlet+1); char afterlet = (char)(asciiplus1); String afterletstring = “ “ + afterlet + __________;
36
Escape sequence for the next line
\n
37
Escape sequence for the next tab
\t
38
Method of the Math class: power
Math.pow(___,power no.);
39
Method of the Math class: square root
Math.sqrt(____);
40
Method of the Math class: round off
Math.round(____);
41
Method of the Math class: absolute value (make it positive)
Math.abs(____);
42
Method of the Math class: random (range of numbers)
int num = (int)(Math.random()*(max - min + 1)) + min; double num = Math.random(); outputs from 0 - 1
43
Method of the Math class: rounding off more than one decimal place. E.g. 2 decimal places
double num = ______; num = num*100; num = Math.round(num); num = num/100;
44
PI, field of the Math class
double area = Math.PI*Math.pow(_____,2);
45
String method to Upper case & Lower case
String ______ = ______.toUpperCase(); String ______ = ______.toLowerCase();
46
Correct way to instantiate a String
String ___ = new String (“____”);
47
Relational Operators
> and < >= and <= (greater than equal to and less than equal to) != and == (not equal and equal)
48
Show Message Dialog
JOptionPane.showMessageDialog(null, _____ , “TITLE OF THE MESSAGE BOX”, JOptionPane.PLAIN_MESSAGE) Message options: PLAIN_MESSAGE ERROR_MESSAGE INFORMATION_MESSAGE WARNING_MESSAGE QUESTION_MESSAGE
49
Find the first digit of a number (2 digit no.)
int digit1 = ______/10;
50
Find the second digit of a number (2 digit no.)
int digit2 = ______%10;
51
The middle letter of a word (odd)
String word = “_____”; int len = word.length(); int middle = (int)(len/2); char midlet = word.charAt(middle);
52
First half and second half of a word (even)
String word = “____”; int len = word.length(); String firsthalf = word.substring(0,len/2); String secondhalf = word.substring(len/2);