1)Java Programs including:
1.1) application: main()1.2) applets: init() and paint()
import java.awt.*;
public class RootApplet extends javax.swing.JApplet{
int number;
public void init(){
number = 225;
}
public void paint(Graphics screen){
Graphics2D screen2D = (Graphics2D) screen;
screen2D.drawString("The square root of " + number + " is " + Math.sqrt(number), 10, 50);
}
}
2) int
final int TOUCH = 6; //TOUCH is a constantint x = 3;int y = x++ *10; // y = 30, x =4int x = 3;int y = ++x *10;// y =40, x=4int z = 0b0000_1101; // z =13
3) String
You can insert several special characters into a string in this manner. Thefollowing list shows these special characters; note that each is preceded by
a backslash (\).
\’ Single quotation mark
\” Double quotation mark
\\ Backslash
\t Tab
\b Backspace
\r Carriage return
\f Formfeed
\n Newline
public class Test{
public static void main(String[] args) {
String i = "'c'";
i += 1;
i = i.toUpperCase();
i = i.toLowerCase();
System.out.println(i);
System.out.println(i.length());
System.out.println(i.equals("'c'1"));
System.out.println(i.indexOf("c"));
}
}
'c'1
4true1
No comments:
Post a Comment