「java基础练习题目」java 基础题

博主:adminadmin 2023-03-17 12:34:07 253

本篇文章给大家谈谈java基础练习题目,以及java 基础题对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

JAVA 练习题

public class JavaExos {

public static void charInt(String chaine){ //1044

String[] charInt = new String[2];

int count = -1;

char maxChar = 'A';

int[] letterCount = new int[26];

String word = chaine.toLowerCase();

for (int i=0;iword.length();i++) {

int indexOfChar = (byte)word.charAt(i)-97;

letterCount[indexOfChar]++;

if (letterCount[indexOfChar]count || (letterCount[indexOfChar]==count word.charAt(i)maxChar)){

count = letterCount[indexOfChar];

maxChar = word.charAt(i);

}

}

charInt[0] = String.valueOf(maxChar);

charInt[1] = ""+count;

System.out.println(charInt[0]+" "+charInt[1]);

}

public static void getDate(int n){ //1047 这题如果给1,其实是指2000年1月2号.

n++;

int[] getYear = getYear(n);

int year = getYear[0];

int[] getMonth = getMonth(year,getYear[1]);

int month = getMonth[0];

String monthString ;

if(month10) monthString = "0"+String.valueOf(month);

else monthString = String.valueOf(month);

int day = getMonth[1];

System.out.println(year+"-"+monthString+"-"+day+" "+getDayOfWeek(n));

}

private static boolean isBissextile(int n){

if (n%4==0 !(n%100==0n%400!=0))

return true;

else

return false;

}

private static int[] getYear(int n){

int[] getYear = new int[2];

int year = 2000;

while(n0){

if(isBissextile(year)) n -= 366;

else n -= 365;

if (n0) year++;

}

if(isBissextile(year)) n+=366;

else n += 365;

getYear[0] = year;

getYear[1] = n;

return getYear;

}

private static int[] getMonth(int year, int n){

int[] getMonth = new int[2];

int month = 1;

while(n0){

if(month=7 month%2 != 0) n -= 31;

else if (month==2 isBissextile(year) ) n -= 29;

else if (month==2 !isBissextile(year)) n -= 28;

else if(month=7 month%2==0) n -= 30;

else if(month%2==0) n-=31;

else n -= 30;

if (n0) month++;

}

if(month=7 month%2 != 0) n += 31;

else if (isBissextile(year) month==2) n += 29;

else if (!isBissextile(year) month==2) n += 28;

else if(month=7 month%2==0) n += 30;

else if(month%2==0) n+=31;

else n += 30;

getMonth[0] = month;

getMonth[1] = n;

return getMonth;

}

private static String getDayOfWeek(int n){

int quotient = n/7;

int remainder = n -= quotient*7;

switch(remainder){

case 0 : return "Sunday";

case 1 : return "Monday";

case 2 : return "Tuesday";

case 3 : return "Wednesday";

case 4 : return "Thursday";

case 5 : return "Friday";

case 6 : return "Saturday";

default : return "Never arrive";

}

}

public static void getCode(String chaine){ //1048

chaine = chaine.toUpperCase();

System.out.println("START");

System.out.println(chaine);

System.out.println("END");

System.out.println();

for(int i=0;ichaine.length();i++){

System.out.print((changChar(chaine.charAt(i))));

}

System.out.println();

}

private static char changChar(char c){

if(c=65 c=90 c-565) return (char)(c+26-5);

else if(c=65 c=90) return (char)(c-5);

else return c;

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

JavaExos.charInt("adfadffasdfda");

JavaExos.getDate(1751);

JavaExos.getCode("NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX");

Java 基础练习

1.C 2.A 3.D

1.ACD 2.CDE

550

public class shuzu{

public static void main( String args[ ])

{

int sum=0;

int b[ ][ ]={{13,14,15},{23,24,25},{33,34,35}};

for ( int i=0;ib.length; i++)

{

System.out.print("b["+i+"]: ");

for (int j=0;jb[i].length;j++)

{

System.out.print(b[i][j]+" ");

sum+=b[i][j];

}

System.out.println();

}

System.out.println("sum="+sum);

}

}

JAVA练习题 对的多且做得快的给30分

1.当一个类没有显式定义构造方法时,Java系统总是为其创建一个默认的无参的构造方法。

2.一个源文件中最多只能包含一个包声明语句(package)。

3.在同一个类的不同构造方法中调用该类的其它构造方法需要使用this(…)的形式,this(…)不能在构造方法的第一行调用。

4.子类可以重写一个父类的构造方法。

5.类File重写方法equals()在两个实例对象的内容和类型一致时返回true。

6.如果一个类没有使用extends关键字扩展任何类,则该类无父类。

7.Math类是final类,因此在被其他类继承时其中的方法不能被重写。

8.Component类是所有界面组件的父类。

9.Frame类默认的布局管理器是BorderLayout,Dialog类没有默认的布局管理器。

错 Dialog类默认的布局管理器也是BorderLayout

10.调用sleep()方法可以使一个线程停止运行。

错 线程休眠(暂停执行)

11.一个新线程启动start()方法,表示线程可为JVM的线程调度程序调度而不表示它可以立即运行。

java基础练习题目的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java 基础题、java基础练习题目的信息别忘了在本站进行查找喔。