【汇智学堂】JAVA基础(1)
作者:互联网
java 基础学习很简单,一本好书,三遍。
第一遍,大概看一遍;
第二遍,仔细看一遍记笔记;
第三遍,从前到后完整敲一遍,从“hello,world”开始。
public class Hello_world {
public static void main(String[]args){
System.out.println("Hello,World!");
}
}
import java.awt.*;
import java.applet.*;
public class APPlet extends Applet{
public void paint(Graphics g){
g.drawString("千山鸟飞绝,万径人踪灭。孤舟蓑笠翁,独钓寒江雪。",20,20);
}
}
public class sample {
public static void main(String[]args){
char ch1,ch2;
ch1=65;
ch2='B';
System.out.println("ch1 and ch2:"+ch1+""+ch2);
}
}
public class sample2 {
public static void main (String[]args){
char ch1;
ch1='A';
ch1++;
System.out.println("ch1 is:"+ch1);
}
}
public class sample3 {
public static void main (String[]args){
int x,y;
float z=3.14f;
double w=3.1415;
char c;
String str;
String str1="bye";
c='A';
str="Hello!Welcome!";
x=6;
y=1000;
System.out.println("int x="+x);
System.out.println("int y="+y);
System.out.println("float z="+z);
System.out.println("double w="+w);
System.out.println("char c="+c);
System.out.println("String str="+str);
}
}
public class sample4 {
public static void main(String args[]){
byte b;
int i=257;
double d=123.456;
System.out.println("Casting of int to byte.");
b=(byte) i;
System.out.println("b is:"+b);
System.out.println("Casting of double to int.");
i=(int)d;
System.out.println("i is:"+i);
}
}
public class sample5 {
public void implictCasting(){
byte a=0x60;
int ia=a;
char b='a';
int c=b;
long d=c;
long e=1000000000L;
float f=e;
double g=f;
String s="hello";
Object o=s;
}
public void explicitCasting(){
long l=1000000L;
int i=(int)l;
double d=12345.678;
float f=(float)d;
Object o=new String("Hello");
String str=(String)o;
}
}
标签:JAVA,String,int,System,汇智,学堂,println,public,out 来源: https://blog.csdn.net/weixin_44711285/article/details/97164086