Cheatography
https://cheatography.com
data types
boolean = true, false
char = 16 bit, UTF-16
byte = 8 bit, -128...127
short = 16 bit, -32.768 ... 32.767
int = 32 bit, -231 to +231-1
long =64 bit, -263 to +263-1,long x = 100l;
float = 32 bit
double =64 bit |
Intro assi 2
public class Main {
public static void main(String[] args) {
// write your code here
int count = 1;
while(count>0)
{
drawX();
box();
Xbox();
count--;
}
}
public static void drawX()
{
System.out.println("\\ /");
System.out.println(" \\ /");
System.out.println(" \\ /" );
System.out.println(" \\/" );
System.out.println(" /\\ ");
System.out.println(" / \\");
System.out.println(" / \\");
System.out.println("/ \\");
}
public static void box()
{
System.out.println("\"\'\'\'\'\'\'\'\" ");
System.out.println("\"\t\t\"");
System.out.println("\"\t\t\"");
System.out.println("\"\t\t\"");
System.out.println("\"\t\t\"");
System.out.println("\"\t\t\"");
System.out.println("\"\t\t\"");
System.out.println("\"\'\'\'\'\'\'\'\" ");
}
public static void Xbox()
{
System.out.print("\\ /");
System.out.println("\"\'\'\'\'\'\'\'\"");
System.out.print(" \\ /");
System.out.println(" \"\t\t\"");
System.out.print(" \\ /");
System.out.println(" \"\t\t\"");
System.out.print(" \\/");
System.out.println(" \"\t\t\"");
System.out.print(" /\\");
System.out.println(" \"\t\t\"");
System.out.print(" / \\");
System.out.println(" \"\t\t\"");
System.out.print(" / \\");
System.out.println(" \"\t\t\"");
System.out.print("/ \\");
System.out.println("\"\'\'\'\'\'\'\'\"");
}
|
|
|
Intro assi 1
public class Main {
public static void main(String[] args) {
String numbers ="0246897531";
drawZero();
drawOne();
drawTwo();
drawThree();
drawFour();
drawFive();
drawSix();
drawSeven();
drawEight();
drawNine();
drawNumber("0246897531");
}
public static void drawZero(){
System.out.println("0000000");
System.out.println("0 0");
System.out.println("0 0");
System.out.println("0 0");
System.out.println("0000000");
}
public static void drawOne(){
System.out.println(" 1");
System.out.println("1 1");
System.out.println(" 1");
System.out.println(" 1");
System.out.println("1111111");
}
public static void drawTwo(){
System.out.println("2222222");
System.out.println(" 2");
System.out.println("2222222");
System.out.println("2");
System.out.println("2222222");
}
public static void drawThree(){
System.out.println("3333333");
System.out.println(" 3");
System.out.println("3333333");
System.out.println(" 3");
System.out.println("3333333");
}
public static void drawFour(){
System.out.println("4 4");
System.out.println("4 4");
System.out.println("4444444");
System.out.println(" 4");
System.out.println(" 4");
}
public static void drawFive(){
System.out.println("5555555");
System.out.println("5");
System.out.println("5555555");
System.out.println(" 5");
System.out.println("5555555");
}
public static void drawSix(){
System.out.println("6666666");
System.out.println("6");
System.out.println("6666666");
System.out.println("6 6");
System.out.println("6666666");
}
public static void drawSeven(){
System.out.println("7777777");
System.out.println(" 7");
System.out.println(" 7");
System.out.println(" 7");
System.out.println(" 7");
}
public static void drawEight(){
System.out.println("8888888");
System.out.println("8 8");
System.out.println("8888888");
System.out.println("8 8");
System.out.println("8888888");
}
public static void drawNine(){
System.out.println("9999999");
System.out.println("9 9");
System.out.println("9999999");
System.out.println(" 9");
System.out.println("9999999");
}
public static void drawNumber(String numbers){
int index = 0;
while(index<numbers.length()) {
if(numbers.charAt(index)=='0')
drawZero();
else if(numbers.charAt(index)=='1')
drawOne();
else if(numbers.charAt(index)=='2')
drawTwo();
else if(numbers.charAt(index)=='3')
drawThree();
else if(numbers.charAt(index)=='4')
drawFour();
else if(numbers.charAt(index)=='5')
drawFive();
else if(numbers.charAt(index)=='6')
drawSix();
else if(numbers.charAt(index)=='7')
drawSeven();
else if(numbers.charAt(index)=='8')
drawEight();
else if (numbers.charAt(index)=='9')
drawNine();
index++;
|
|
|
Java escape sequences
* Asterisk (*)
^ Carat (^)
` Backtick (`)
\t Tab
\b Backspace
\n New line
\r Carriage return |
swap code
public static void swap(int[] list, int e1, int e2){
int temp;
temp = list[e1];
list[e1] = list[e2];
list[e2] = temp;
for (int i: list){
System.out.println(i);
}
}
public static void main(String[] args){
int[] mylist = {1,2,3,4,5};
swap(mylist, 0, 3);
}
|
For loop array
string word = "Hello";
for (char c: word toCharArray(){
system.out.print()
}
|
Class
public class ABCD{
public A () {
//code
}
public void B(){
//code
}
|
Operators
+ ( Addition )
Adds values on either side of the operator
- ( Subtraction )
Subtracts right hand operand from left hand operand
* ( Multiplication )
Multiplies values on either side of the operator
/ (Division)
Divides left hand operand by right hand operand
% (Modulus)
Divides left hand operand by right hand operand and returns remainder
++ (Increment)
Increases the value of operand by 1
-- ( Decrement )
Decreases the value of operand by 1 |
|
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by khaowpoon101