当编译并运行下列代码时,其运行结果是什么?
Public class Main{
public static void main(String args]){
String s="Hello";
methodA(s);
s=s.replace('e', 'a');
System.out.println(s);
}
public static void methodA(String str){
str+="World";
}
}
上述代码的运行结果为:()
Public class Main{
public static void main(String args]){
String s="Hello";
methodA(s);
s=s.replace('e', 'a');
System.out.println(s);
}
public static void methodA(String str){
str+="World";
}
}
上述代码的运行结果为:()
以下文字与答案无关
提示:有些试题内容 显示不完整,文字错误 或者 答案显示错误等问题,这是由于我们在扫描录入过程中 机器识别错误导致,人工逐条矫正总有遗漏,所以恳请 广大网友理解。
String s2 = "lanqiao";
String s3 = new String("lanqiao");
String s4 = new String("lanqiao");
System.out.println(s1==s2);
System.out.println(s3==s4);
}
}
程序运行后的输出结果是( )
选项: A:true false
C:false false
D:false true
">1.1.有如下程序
public class LanQiao{
public static void main(String] args) {
String s1 = "lanqiao";
String s2 = "lanqiao";
String s3 = new String("lanqiao");
String s4 = new String("lanqiao");
System.out.println(s1==s2);
System.out.println(s3==s4);
}
}
程序运行后的输出结果是( )
选项: A:true false
C:false false
D:false true
s2 = new String();
s2 = "study hard.";
System.out.print(s1);
System.out.println(s2);
s2 = "learn english, too";
System.out.print(s1);
System.out.println(s2);
s2 = s1 + s2;
System.out.println(s2);
}
}
">2.6.阅读程序,写出运行结果public class StringUse {
public static void main(String] args) {
String s1, s2;
s1 = new String("Students should ");
s2 = new String();
s2 = "study hard.";
System.out.print(s1);
System.out.println(s2);
s2 = "learn english, too";
System.out.print(s1);
System.out.println(s2);
s2 = s1 + s2;
System.out.println(s2);
}
}
System.out.println(" *** ");
System.out.println(" ***** ");
}
}
">3.阅读程序,写出下面程序运行结果。/* Practice1_1.java */
public class Practice1_1 {
public static void main(String] args) {
System.out.println(" * ");
System.out.println(" *** ");
System.out.println(" ***** ");
}
}
import java.io.*;
public class E {
public static void main(String args]) {
int n=-1;
File f =new File("hello.txt");
byte ] a="abcd".getBytes();
try{ FileOutputStream out=new FileOutputStream(f);
out.write(a);
out.close();
FileInputStream in=new FileInputStream(f);
byte ] tom= new byte3];
int m = in.read(tom,0,3);
System.out.println(m); //【代码1】
String s=new String(tom,0,3);
System.out.println(s); //【代码2】
m = in.read(tom,0,3);
System.out.println(m); //【代码3】
s=new String(tom,0,3);
System.out.println(s); //【代码4】
}
catch(IOException e) {}
}
}(2.0分)
byte ] a="abcd".getBytes();
try{ FileOutputStream out=new FileOutputStream(f);
out.write(a);
out.close();
FileInputStream in=new FileInputStream(f);
byte ] tom= new byte3];
int m = in.read(tom,0,3);
System.out.println(m);
String s=new String(tom,0,3);
System.out.println(s);
m = in.read(tom,0,3);
System.out.println(m);
s=new String(tom,0,3);
System.out.println(s);
}
catch(IOException e) {}
}
}
">5.以下程序的运行结果是( )。import java.io.*;
public class E {
public static void main(String args]) {
int n=-1;
File f =new File("hello.txt");
byte ] a="abcd".getBytes();
try{ FileOutputStream out=new FileOutputStream(f);
out.write(a);
out.close();
FileInputStream in=new FileInputStream(f);
byte ] tom= new byte3];
int m = in.read(tom,0,3);
System.out.println(m);
String s=new String(tom,0,3);
System.out.println(s);
m = in.read(tom,0,3);
System.out.println(m);
s=new String(tom,0,3);
System.out.println(s);
}
catch(IOException e) {}
}
}
try{
FileOutputStream out=new FileOutputStream(f) ;
out.write(a) ;
out.close () ;
FileInputStream in=new FileInputStream(f);byte ] tom= new byte100];
int m = in.read(tom) ;
String s=new String(tom,0, m) ;
System.out.printf("%d : %s" , m,s);
}catch (IOException e){}
}
}
">6.阅读以下程序,写出输出结果:import java.io.*;
public class E{
public static void main(String args]){
int n=-1;
File f =new File("hello.txt") ;byte ] a="abcd".getBytes () ;
try{
FileOutputStream out=new FileOutputStream(f) ;
out.write(a) ;
out.close () ;
FileInputStream in=new FileInputStream(f);byte ] tom= new byte100];
int m = in.read(tom) ;
String s=new String(tom,0, m) ;
System.out.printf("%d : %s" , m,s);
}catch (IOException e){}
}
}
out.write(a);
out.close();
FileInputStream in = new FileInputStream(f);
byte ] tom = new byte3];
int m = in.read(tom,0,3);
System.out.println(m); //代码1] (3)
String s = new String(tom,0,3);
System.out,println(s): //代码2](abc)
m= in.read(tom,0,3);
System.out.println(m) //代码3] (1)
s =new String(tom,0,3)
System.out.println(s): //代码4] (abc)
catch(IOException e)(]
">7.请说出 E类中标注的代码 1]一代码4]的输出结果import java.io.;public class E(public static void main(String args ]) (intn=-1;File f = new File("hello.txt");byte] a= "abcd".getBytes();try| FileOutputStream out = new FileOutputStream(f);
out.write(a);
out.close();
FileInputStream in = new FileInputStream(f);
byte ] tom = new byte3];
int m = in.read(tom,0,3);
System.out.println(m); //代码1] (3)
String s = new String(tom,0,3);
System.out,println(s): //代码2](abc)
m= in.read(tom,0,3);
System.out.println(m) //代码3] (1)
s =new String(tom,0,3)
System.out.println(s): //代码4] (abc)
catch(IOException e)(]
for (int i=0;i<list.length;i++)
System.out.print(listi]+" ");
System.out.println();
}
public static void main(String] args){
int] list1={0,1,2,3};
int] list2=new intlist1.length];
list2=list1;
PrintLst("数组1",list1);
PrintLst("数组2",list2);
list12]=list12]+10;
PrintLst("修改数组1后,数组2为",list2);
}}
">9.阅读下列程序,并给出程序运行的结果。Public class CopyArray{
public static void PrintLst(String s,int] list){
System.out.print(s+":");
for (int i=0;i<list.length;i++)
System.out.print(listi]+" ");
System.out.println();
}
public static void main(String] args){
int] list1={0,1,2,3};
int] list2=new intlist1.length];
list2=list1;
PrintLst("数组1",list1);
PrintLst("数组2",list2);
list12]=list12]+10;
PrintLst("修改数组1后,数组2为",list2);
}}
Byte]a= "abcd" . getBytes();
Try{ FileOutputStream out = new FileOutputStream(f);
Out.write(a);
Out.close();
FileInputStream in = new FileInputStream(f);
Byte] tom= new byte 3];
Int m= in. read(tom, 0,3);
System. out. println(m);//【代码1】
String s = new String(tom, 0, 3);
System. out. println(s); //代码2】
M= in.read(tom, 0, 3);
System. out. println(m);//代码3】
S = new String( tom, 0,3);
System. out. println(s);//【代码4】
Catch( IOException e){}
}
}
">10.请说出E类中标注的【代码1】~【代码4】的输出结果。Import java.io. *;
Public class E{
Public static void main(String args ]){
Int n= - 1;
File f = new File( " hello.txt");
Byte]a= "abcd" . getBytes();
Try{ FileOutputStream out = new FileOutputStream(f);
Out.write(a);
Out.close();
FileInputStream in = new FileInputStream(f);
Byte] tom= new byte 3];
Int m= in. read(tom, 0,3);
System. out. println(m);//【代码1】
String s = new String(tom, 0, 3);
System. out. println(s); //代码2】
M= in.read(tom, 0, 3);
System. out. println(m);//代码3】
S = new String( tom, 0,3);
System. out. println(s);//【代码4】
Catch( IOException e){}
}
}
for(int i=0; i<a.length; i++) {
ai] = i+1;
System.out.println("\ta" + i + "]=" + ai]);
}
}
}
">11.阅读下列程序,并给出程序运行的结果。class exam2{
public static void main(String args]) {
int a] = new int 3];
System.out.println("\t输出一维数组a:");
for(int i=0; i<a.length; i++) {
ai] = i+1;
System.out.println("\ta" + i + "]=" + ai]);
}
}
}
}
class Beta extends Alpha {
String getType() { return "beta"; }
}
class Gamma extends Beta {
String getType() { return "gamma"; }
public static void main(String] args) {
Alpha g1 = new Beta();
Alpha g2 = new Gamma();
System.out.println(g1.getType() + " " + g2.getType());
}
}
选项: A:alpha alpha
B:gamma gamma
C:alpha beta
D:beta gamma
">12.下面程序运行结果为( )。class Alpha {
String getType() { return "alpha"; }
}
class Beta extends Alpha {
String getType() { return "beta"; }
}
class Gamma extends Beta {
String getType() { return "gamma"; }
public static void main(String] args) {
Alpha g1 = new Beta();
Alpha g2 = new Gamma();
System.out.println(g1.getType() + " " + g2.getType());
}
}
选项: A:alpha alpha
B:gamma gamma
C:alpha beta
D:beta gamma
public void printMyGender(String s){
this.print();
System.out.print(s+" ");
}
}
class Gender{
String type="gender";
public void print(Person p){p.printMyGender(type);}
}
class Female extends Gender{
public Female(){
type="female";
}
}
class Male extends Gender{
public Male(){
type="male";
}
}
class Employee extends Person{
public void print(){
System.out.print("Employee ");}
}
class Manager extends Employee{
public void print(){
System.out.print("Manager ");}
}
public class Test{
public static ">13.import java.io.*;
class Person{
public void print(){System.out.print("Person ");}
public void printMyGender(String s){
this.print();
System.out.print(s+" ");
}
}
class Gender{
String type="gender";
public void print(Person p){p.printMyGender(type);}
}
class Female extends Gender{
public Female(){
type="female";
}
}
class Male extends Gender{
public Male(){
type="male";
}
}
class Employee extends Person{
public void print(){
System.out.print("Employee ");}
}
class Manager extends Employee{
public void print(){
System.out.print("Manager ");}
}
public class Test{
public static
public void printMyGender(String s){
this.print();
System.out.print(s+" ");
}
}
class Gender{
String type="gender";
public void print(Person p){p.printMyGender(type);}
}
class Female extends Gender{
public Female(){
type="female";
}
}
class Male extends Gender{
public Male(){
type="male";
}
}
class Employee extends Person{
public void print(){
System.out.print("Employee ");}
}
class Manager extends Employee{
public void print(){
System.out.print("Manager ");}
}
public class Test{
public static ">14.import java.io.*;
class Person{
public void print(){System.out.print("Person ");}
public void printMyGender(String s){
this.print();
System.out.print(s+" ");
}
}
class Gender{
String type="gender";
public void print(Person p){p.printMyGender(type);}
}
class Female extends Gender{
public Female(){
type="female";
}
}
class Male extends Gender{
public Male(){
type="male";
}
}
class Employee extends Person{
public void print(){
System.out.print("Employee ");}
}
class Manager extends Employee{
public void print(){
System.out.print("Manager ");}
}
public class Test{
public static
}
}
class Rectangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Rectangle");
}
}
class Triangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Triangle");
}
}
public class AbstractClassDemo{
public static void main(String args]){
(new Circle()).display();//定义无名对象来调用对应的display方法
(new Rectangle()).display();
(new Triangle()).display();
}
}
输出结果是 ?
">15.阅读程序,给出结果:// AbstractClassDemo.java源代码如下:
abstract class Shape { //定义抽象类Shape和抽象方法display
abstract void display();
}
class Circle extends Shape {
void display() {//实现抽象类的方法
System.out.println("Circle");
}
}
class Rectangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Rectangle");
}
}
class Triangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Triangle");
}
}
public class AbstractClassDemo{
public static void main(String args]){
(new Circle()).display();//定义无名对象来调用对应的display方法
(new Rectangle()).display();
(new Triangle()).display();
}
}
输出结果是 ?
}
}
class Rectangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Rectangle");
}
}
class Triangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Triangle");
}
}
public class AbstractClassDemo{
public static void main(String args]){
(new Circle()).display();//定义无名对象来调用对应的display方法
(new Rectangle()).display();
(new Triangle()).display();
}
}
输出结果是 ?
">16.阅读程序,给出结果:// AbstractClassDemo.java源代码如下:
abstract class Shape { //定义抽象类Shape和抽象方法display
abstract void display();
}
class Circle extends Shape {
void display() {//实现抽象类的方法
System.out.println("Circle");
}
}
class Rectangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Rectangle");
}
}
class Triangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Triangle");
}
}
public class AbstractClassDemo{
public static void main(String args]){
(new Circle()).display();//定义无名对象来调用对应的display方法
(new Rectangle()).display();
(new Triangle()).display();
}
}
输出结果是 ?
上述代码的运行结果是:()
选项: A:MyClass() 20 MyClass(int) 10
B:In Static MyClass() 20 MyClass(int) 10
C:In Static MyClass(int) 20 MyClass() 10
D:In Static MyClass() 10 MyClass(int) 20
">17.上述代码的运行结果是:()
选项: A:MyClass() 20 MyClass(int) 10
B:In Static MyClass() 20 MyClass(int) 10
C:In Static MyClass(int) 20 MyClass() 10
D:In Static MyClass() 10 MyClass(int) 20
错误:方法参数与变量不匹配
B:20 and 40
C:10 and 40
D:10 and 20
">18.以下代码的输出结果为( )。public class Pass{
static int j = 20;
public void amethod(int x){
x = x*2;
j = j*2;
}
public static void main(String args]){
int i = 10;
Pass p = new Pass();
p.amethod(i);
System.out.println(i+" and "+j);
}
}
错误:方法参数与变量不匹配
B:20 and 40
C:10 and 40
D:10 and 20
}
}
">20.14、请说出下面中【代码】的输出结果
interface Com {
int add(int a,int b);
public static int get(int n){
return n;
}
public default int see(int n){
return n;
}
public default int look(int n){
return n;
}
}
class A implements Com{
public int add(int a,int b) {
return a+b;
}
public int see(int n){
return n+1;
}
}
public class Main {
public static void main(String args]) {
A a = new A();
int m = a.add(12,6);
int n =Com.get(12);
int t = a.see(6);
int q = a.look(6);
System.out.printf("%d:%d:%d:%d",m,n,t,q); //【代码】
}
}
}
}
">21.请说出下面中【代码】的输出结果
interface Com {
int add(int a,int b);
public static int get(int n){
return n;
}
public default int see(int n){
return n;
}
public default int look(int n){
return n;
}
}
class A implements Com{
public int add(int a,int b) {
return a+b;
}
public int see(int n){
return n+1;
}
}
public class Main {
public static void main(String args]) {
A a = new A();
int m = a.add(12,6);
int n =Com.get(12);
int t = a.see(6);
int q = a.look(6);
System.out.printf("%d:%d:%d:%d",m,n,t,q); //【代码】
}
}
}
}
class Rectangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Rectangle");
}
}
class Triangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Triangle");
}
}
public class AbstractClassDemo{
public static void main(String args]){
(new Circle()).display();//定义无名对象来调用对应的display方法
(new Rectangle()).display();
(new Triangle()).display();
}
}
abstract class Shape { //定义抽象类Shape和抽象方法display
abstract void display();
}
class Circle extends Shape {
void display() {//实现抽象类的方法
System.out.println("Circle");
}
}
class Rectangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Rectangle");
}
}
class Triangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Triangle");
}
}
public class AbstractClassDemo{
public static void main(String args]){
(new Circle()).display();//定义无名对象来调用对应的display方法
(new Rectangle()).display();
(new Triangle()).display();
}
}