|
byte
|
8 bits
|
|
short
|
16 bits
|
|
int
|
32 bits
|
|
long
|
64 bits
|
|
boolean
|
( no bit just true/ false)
|
|
char
|
16 bit unicode
|
|
float
|
32 bit decimal
|
|
double
|
64 bit decimal
|
package com.company;
import java.lang.System;
public class Main {
public static void swap(int[] list, int e1, int e2)
{
int temp;
temp = list[e1];
list[e1] = list[e2];
list[e2] = temp;
System.out.print("\nafter swap: ");
for (int i = 0; i < 5; i++)
{
System.out.print(list[i] + " ");
}
}
public static void main(String[] args)
{
int [] mylist = new int [] {1, 2, 3, 4, 5};
System.out.print("before swap: ");
for (int i = 0; i < 5; i++)
{
System.out.print(mylist[i] + " ");
}
swap(mylist, 1, 2);
swap(mylist, 0, 4);
swap(mylist, 1, 3);
}
}
- List use when shopping
- can make 2 ways:
int[] ex1 = new int [3];
ex1[0]= 1;
ex2[1]= 2;
ex3[2]= 3;
While loops
int count = 0;
while (count < mylist.lenght) {
System.out.print( mylist[count] + "");
count ++;
- It make the code run and check the condition.
(if the condition correct or not and have 1 letter)
int count=0;
do{
System.out.print(count + " ");
count ++ ;
}while (count < 10);
Ans 0 1 2 3 4 5 6 7 8 9
For loops (do everything in () )
Characters
String name = "yuyu";
for (char y : name.toCharArray()){
System.out.print(y + " ");
}
Ans y u y u
int [] mylist = {2,4,6};
for (int i = 0; i < mylist.length; i++)
{
System.out.print( mylist [i] + " ");
}
Ans 2 4 6
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.