本文目錄一覽:
- 1、幾道JAVA題目,求好心人給下答案,感激不盡
- 2、急求下列 java 程序題答案!請各位多多幫忙
- 3、求高手幫忙做幾道java編程題,我是新手,都不會!謝謝!
- 4、急。java編程題求解。5個小題,高手進
- 5、5道簡單java選擇題
- 6、5道簡單的JAVA編程題(高分懸賞)
幾道JAVA題目,求好心人給下答案,感激不盡
1、public static void main(String[] args)
2、public finall static
3、3
4、抽象類
5、implements
6、類:一個包含屬性、方法,使用class關鍵字定義
對象:創建對象必須使用new關鍵字,對象其實在內存中存儲的是類的引用地址。
7、try是可能發生異常的內容;
catch是發生異常後要處理的代碼;
finally是始終執行的,比如關閉資源等。
8、
public class Demo {
//小明今年12歲,他母親比他大20歲。編程計算多少年後他母親的年齡是小明的2倍。
public static void main(String[] args) {
System.out.println(getYeah());
}
public static int getYeah(){
int xmAge = 12,mqAge = 20,yeah = 0;
while(true){
if(mqAge / 2 == xmAge){
return yeah;
}
mqAge++;
yeah++;
}
}
}
9、
public class Demo {
public static void main(String[] args) {
new Thread(new Piao()).start();
new Thread(new Piao()).start();
new Thread(new Piao()).start();
new Thread(new Piao()).start();
}
}
class Piao implements Runnable{
private static int piao = 1;
public void run(){
while(true){
synchronized(Piao.class){
if(piao 100){
System.exit(0);
}
System.out.println(Thread.currentThread().getName()+”出票:” + piao + “號”);
piao++;
}
}
}
}
急求下列 java 程序題答案!請各位多多幫忙
第一題
publci
class
Jiechen
public
staic
void
main(String[]
args){
int[]
intNum={2,4,6,10};
long
result=1;
for(int
i=0,i
=50)
intGeshu++;
}
Arrays.sort(intrndNum);//對數組進行從小到大排序
System.out.println(intGeshu);//列印大於50的個數
System.out.println(“最小值”+intrmdNum[0]);
System.out.println(“最大值”+intrmdNum[99]);
}
}
呵呵
我忘了最大公約數概念了,
第六題也比較簡單哦
通過Switch語句進行判斷,關鍵要對價格當成字元串處理,
求高手幫忙做幾道java編程題,我是新手,都不會!謝謝!
#includestdio.h
#define N 10
/*列印出楊輝三角形*/
int main()
{
int num[N][N];
int i=0,j=0;
num[0][0]=1;
num[1][0]=1,num[1][1]=1;
for(i=2;iN;i++)
{
num[i][0]=1;
for(j=1;ji;j++)
{
num[i][j]=num[i-1][j-1]+num[i-1][j];
}
num[i][i]=1;
}
for(i=0;iN;i++)
{
for(j=0;j=i;j++)
{
printf(” %d”,num[i][j]);
}
printf(“\n”);
}
getch();
}
急。java編程題求解。5個小題,高手進
第一題應該是參數名的命名吧,自己去查查吧,我也不記得了,實際工作中不會這麼刁難的。
第二題 int i char a 這兩個變數根本沒有賦值,你輸出什麼呢?
第三題真不會,不知道你寫得什麼,d是確定的,最下面3個式子你要求什麼?還有a的類型都沒有,不會算,我也求教
第四題,樓上有正解,照抄了
第0個元素值為1
第1個元素值為3
第2個元素值為7
第3個元素值為2
第4個元素值為6
第5個元素值為5
java.util.GregorianCalendar[time=1323836914287,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id=”Asia/Shanghai”,offset=28800000,dstSavings=0,useDaylight=false,transitions=19,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=11,WEEK_OF_YEAR=51,WEEK_OF_MONTH=3,DAY_OF_MONTH=14,DAY_OF_YEAR=348,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=0,HOUR_OF_DAY=12,MINUTE=28,SECOND=34,MILLISECOND=287,ZONE_OFFSET=28800000,DST_OFFSET=0]
第5題
import java.util.*;
public class Test1 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(“輸入長方形的長:”);
int chang = scan.nextInt();
System.out.println(“輸入長方形的寬:”);
int kuan = scan.nextInt();
int area = chang * kuan;
System.out.println(“長方形的面積:”+area);
}
}
5道簡單java選擇題
6、 已知有一個多線程類myThread,除run方法外還包含一個方法void disp()。以下說法正確的是【 】
A) myThread mt=new myThread(); mt.start();mt.disp();運行完線程體run方法後再運行disp()方法
B) myThread mt=new myThread();mt.disp();mt.start();運行完disp()後才能啟動線程體run
C) myThread mt=new myThread();mt.start();mt.disp();線程體run一定會在disp結束前結束。
D) myThread mt=new myThread();mt.start();mt.disp();mt.start()和mt.disp()兩條命令,哪條放在前面哪條放在後面運行結果一樣。
7、 以下說法不正確的是【 】
A) private修飾的成員變數可以在本類或其本包中子類中使用 不正確,只能在本類中訪問
B) java類可以同時實現多個介面,但只能繼承一個父類 正確
C) static修飾的成員變數可以不經過實例化直接通過類名引用 正確
D) static不可以和abstract修飾符同時使用。 正確
8、 在myweb.htm頁面中有如下代碼,下列說法不正確的是【 】
applet width=”400″ height=”300″ code=”myClock.class” archive=”c.jar”
/applet
A) 打包命令jar cf c.jar myClock.class。正確
B) myClock類必須是Applet的子類。 正確
C) myClock類不能獨立運行。 錯誤
D) myClock.class必須放在myweb.htm所在目錄下。正確
9、 有如下代碼:
public class T {
private int a = 10;
int m = 12;
static int n=1;
public static void main(String arg[]) {
T t = new T ();
System.out.println(__________);
} }
在空格處如下哪個使用是錯誤的?【 】
A) t.f
B) this.m 錯誤,靜態方法中不能使用非靜態的this對象
C) t.m
D) T.n
10、 有類Copy編譯後產生如下錯誤提示,需要修改的地方是【 】
import java.io.*;
運行時提示錯誤為:
Copy.java:11:可能損失精度
找到:int
需要:char
while((c=in.read())!=-1)
public class Copy
{ public static void main(String[] args) throws Exception
{File inputFile = new File(“in.txt”);
File outputFile = new File(“out.txt”);
FileReader in = new FileReader(inputFile); ①
FileWriter out = new FileWriter(outputFile);
char c; ②
while ((c = in.read()) != -1) ③
out.write(c); ④
in.close();
out.close();
}
}
A) ①
B) ②
C) ③ IO操作可能殘生異常
D) ④
我的答案是: BACBC
5道簡單的JAVA編程題(高分懸賞)
很詳細的幫你寫下,呵呵,所以要給分哦!
1、
(1)源程序如下:
public class One {
public static void main(String[] args) {
String name = “張三”;
int age = 23;
char sex = ‘男’;
String myclass = “某某專業2班”;
System.out.println(“姓名:” + name);
System.out.println(“姓名:” + age);
System.out.println(“姓名:” + sex);
System.out.println(“姓名:” + myclass);
}
}
(2)
編寫完程序的後綴名是.java,如本題,文件名就是One.java。
開始\運行\cmd,進入「命令提示符窗口」,然後用javac編譯器編譯.java文件,語句:javac One.java。
(3)
編譯成功後,生成的文件名後綴是.class,叫做位元組碼文件。再用java解釋器來運行改程序,語句:java One
2、編寫程序,輸出1到100間的所有偶數
(1)for語句
public class Two1 {
public static void main(String[] args) {
for(int i=2;i=100;i+=2)
System.out.println(i);
}
}
(2)while語句
public class Two2 {
public static void main(String[] args) {
int i = 2;
while (i = 100) {
System.out.println(i);
i += 2;
}
}
}
(3)do…while語句
public class Two3 {
public static void main(String[] args) {
int i = 2;
do {
System.out.println(i);
i += 2;
}while(i=100);
}
}
3、編寫程序,從10個數當中找出最大值。
(1)for循環
import java.util.*;
public class Three1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
for (int i = 0; i 10; i++) {
System.out.print(“輸入第” + (i + 1) + “個數:”);
number = input.nextInt();
if (max number)
max = number;
}
System.out.println(“最大值:” + max);
}
}
(2)while語句
import java.util.*;
public class Three2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
int i = 0;
while (i 10) {
System.out.print(“輸入第” + (i + 1) + “個數:”);
number = input.nextInt();
if (max number)
max = number;
i++;
}
System.out.println(“最大值:” + max);
}
}
(3)do…while語句
import java.util.*;
public class Three3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
int i = 0;
do {
System.out.print(“輸入第” + (i + 1) + “個數:”);
number = input.nextInt();
if (max number)
max = number;
i++;
}while(i10);
System.out.println(“最大值:” + max);
}
}
4、編寫程序,計算從1到100之間的奇數之和。
(1)for循環
public class Four1 {
public static void main(String[] args) {
int sum=0;
for(int i = 1;i=100;i+=2){
sum+=i;
}
System.out.println(“1~100間奇數和:” + sum);
}
}
(2)while語句
public class Four2 {
public static void main(String[] args) {
int sum = 0;
int i = 1;
while (i = 100) {
sum += i;
i += 2;
}
System.out.println(“1~100間奇數和:” + sum);
}
}
(3)do…while語句
public class Four3 {
public static void main(String[] args) {
int sum = 0;
int i = 1;
do {
sum += i;
i += 2;
} while (i = 100);
System.out.println(“1~100間奇數和:” + sum);
}
}
5、
(1)什麼是類的繼承?什麼是父類?什麼是子類?舉例說明。
繼承:是面向對象軟體技術當中的一個概念。如果一個類A繼承自另一個類B,就把這個A稱為”B的子類”,而把B稱為”A的父類”。繼承可以使得子類具有父類的各種屬性和方法,而不需要再次編寫相同的代碼。在令子類繼承父類的同時,可以重新定義某些屬性,並重寫某些方法,即覆蓋父類的原有屬性和方法,使其獲得與父類不同的功能。另外,為子類追加新的屬性和方法也是常見的做法。繼承需要關鍵字extends。舉例:
class A{}
class B extends A{}
//成員我就不寫了,本例中,A是父類,B是子類。
(2)編寫一個繼承的程序。
class Person {
public String name;
public int age;
public char sex;
public Person(String n, int a, char s) {
name = n;
age = a;
sex = s;
}
public void output1() {
System.out.println(“姓名:” + name + “\n年齡:” + age + “\n性別:” + sex);
}
}
class StudentPerson extends Person {
String school, department, subject, myclass;
public StudentPerson(String sc, String d, String su, String m, String n,
int a, char s) {
super(n, a, s);
school = sc;
department = d;
subject = su;
myclass = m;
}
public void output2() {
super.output1();
System.out.println(“學校:” + school + “\n系別:” + department + “\n專業:”
+ subject + “\n班級:” + myclass);
}
}
public class Five2 {
public static void main(String[] args) {
StudentPerson StudentPersonDemo = new StudentPerson(“某某大學”, “某某系別”,
” 某專業”, “某某班級”, ” 張三”, 23, ‘男’);
StudentPersonDemo.output2();
}
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/308683.html