public class Test{ public static void main(String args[]){ StringBuffer sBuffer = new StringBuffer("菜鸟教程官网:"); sBuffer.append("www"); sBuffer.append(".runoob"); sBuffer.append(".com"); System.out.println(sBuffer); }…
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //使用 BufferedReader 在控制台读取字符 import java.io.*; public class BRRead { public static void main(String args[]) throws IOException { char c; // 使用 System.in 创建 BufferedReader Buffe…
import java.util.regex.*; class RegexExample1{ public static void main(String args[]){ String content = "I am noob " + "from runoob.com."; String pattern = ".*runoob.*"; boolean isMatch = Pattern.matches(pattern, content); Sy…
public class StringDemo{ public static void main(String args[]){ char[] helloArray = { 'r', 'u', 'n', 'o', 'o', 'b'}; String helloString = new String(helloArray); System.out.println( helloString ); } } public class StringDemo { public static void mai…
public class Variable{ static int allClicks=0; // 类变量 String str="hello world"; // 实例变量 public void method(){ int i =0; // 局部变量 } } public class Test{ public void pupAge(){ int age = 0; age = age + 7; System.out.println("小狗的年龄是: " + ag…
import java.applet.*; import java.awt.*; public class HelloWorldApplet extends Applet { public void paint (Graphics g) { g.drawString ("Hello World", 25, 50); } } <html> <title>The Hello, World Applet</title> <hr> <app…
1:jar可到Mysql官网下载:地址Mysql 连接jar包.:https://dev.mysql.com/downloads/connector/j/如图,在下拉列表框中选择Platform Independent public class Test{ // 定义MySQL的数据库驱动程序 public static final String DBDRIVER = "com.mysql.cj.jdbc.Driver" ; public static void main(String…
这个异常是时区的错误,因此只你需要设置为你当前系统时区即可,解决方案如下: import java.sql.Connection ; import java.sql.DriverManager ; import java.sql.SQLException ; public class Test{ // 定义MySQL的数据库驱动程序 public static final String DBDRIVER = "com.mysql.cj.jdbc.Driver" ; // 定义MySQL…
package test; public class temp { /* 第一个Java程序 * 它将打印字符串 Hello World */ public static void main(String []args) { System.out.println("Hello World"); // 打印 Hello World } } package test; public class temp { int puppyAge; public temp(String name) {…
import java.util.Scanner; public class ScannerDemo { public static void main(String[] args) { Scanner scan = new Scanner(System.in); // 从键盘接收数据 // next方式接收字符串 System.out.println("next方式接收:"); // 判断是否还有输入 if (scan.hasNext()) { String str1 = scan.…
/** 返回两个整型变量数据的较大值 */ public static int max(int num1, int num2) { int result; if (num1 > num2) result = num1; else result = num2; return result; } public class TestMax { /** 主方法 */ public static void main(String[] args) { int i = 5; int j = 2; int k…
import java.util.Date; public class DateDemo { public static void main(String args[]) { // 初始化 Date 对象 Date date = new Date(); // 使用 toString() 函数显示日期时间 System.out.println(date.toString()); } } import java.util.*; import java.text.*; public class Dat…
public class PrimitiveTypeTest { public static void main(String[] args) { // byte System.out.println("基本类型:byte 二进制位数:" + Byte.SIZE); System.out.println("包装类:java.lang.Byte"); System.out.println("最小值:Byte.MIN_VALUE=" + Byte.M…
import java.util.Vector; import java.util.Enumeration; public class EnumerationTester { public static void main(String args[]) { Enumeration<String> days; Vector<String> dayNames = new Vector<String>(); dayNames.add("Sunday");…
package pkg1[.pkg2[.pkg3…]]; package net.java.util; public class Something{ ... } package animals; interface Animal { public void eat(); public void travel(); } package animals; /* 文件名 : MammalInt.java */ public class MammalInt implements Animal{ pub…
[可见度] interface 接口名称 [extends 其他的接口名] { // 声明变量 // 抽象方法 } import java.lang.*; //引入包 public interface NameOfInterface { //任何类型 final, static 字段 //抽象方法 } interface Animal { public void eat(); public void travel(); } public class MammalInt implements An…
try { // 程序代码 }catch(ExceptionName e1) { //Catch 块 } import java.io.*; public class ExcepTest{ public static void main(String args[]){ try{ int a[] = new int[2]; System.out.println("Access element three :" + a[3]); }catch(ArrayIndexOutOfBoundsEx…
CREATE TABLE `websites` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` char(20) NOT NULL DEFAULT '' COMMENT '站点名称', `url` varchar(255) NOT NULL DEFAULT '', `alexa` int(11) NOT NULL DEFAULT '0' COMMENT 'Alexa 排名', `country` char(10) NOT NULL DEFAULT '…
/*** 这个类绘制一个条形图 * @author runoob * @version 1.2 */ import java.io.*; /** * 这个类演示了文档注释 * @author Ayan Amhed * @version 1.2 */ public class SquareNum { /** * This method returns the square of num. * This is a multiline description. You can use * as man…
import java.util.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class SendEmail { public static void main(String [] args) { // 收件人电子邮箱 String to = "abcd@gmail.com"; // 发件人电子邮箱 String from = "web@gmai…
import java.net.*; import java.io.*; public class GreetingClient { public static void main(String [] args) { String serverName = args[0]; int port = Integer.parseInt(args[1]); try { System.out.println("连接到主机:" + serverName + " ,端口号:" +…
public final void writeObject(Object x) throws IOException public final Object readObject() throws IOException, ClassNotFoundException public class Employee implements java.io.Serializable { public String name; public String address; public transient…
public class GenericMethodTest { // 泛型方法 printArray public static < E > void printArray( E[] inputArray ) { // 输出数组元素 for ( E element : inputArray ){ System.out.printf( "%s ", element ); } System.out.println(); } public static void main( S…
import java.util.*; public class Test{ public static void main(String[] args) { List<String> list=new ArrayList<String>(); list.add("Hello"); list.add("World"); list.add("HAHAHAHA"); //第一种遍历方法使用foreach遍历List for (…
char ch = 'a'; // Unicode 字符表示形式 char uniChar = '\u039A'; // 字符数组 char[] charArray ={ 'a', 'b', 'c', 'd', 'e' }; public class Test { public static void main(String args[]) { System.out.println(Character.isLetter('c')); System.out.println(Character.is…
int a = 5000; float b = 13.65f; byte c = 0x4a; public class Test{ public static void main(String args[]){ Integer x = 5; x = x + 10; System.out.println(x); } } public class Test { public static void main (String []args) { System.out.println("90 度的正弦值…
public class Test { public static void main(String args[]){ //char grade = args[0].charAt(0); char grade = 'C'; switch(grade) { case 'A' : System.out.println("优秀"); break; case 'B' : case 'C' : System.out.println("良好"); break; case 'D'…
public class Test { public static void main(String args[]){ int x = 10; if( x < 20 ){ System.out.print("这是 if 语句"); } } } if(布尔表达式){ //如果布尔表达式的值为true }else{ //如果布尔表达式的值为false } public class Test { public static void main(String args[]){ int x…
public class Test { public static void main(String args[]) { int x = 10; while( x < 20 ) { System.out.print("value of x : " + x ); x++; System.out.print("\n"); } } } public class Test { public static void main(String args[]){ int x…