两道简单的面试题,求标准答案

cgh6697067 2008-01-14 01:25:57
1、 写一Application程序,让用户输入姓名,程序输出:“Welcome you, 用户姓名!”(10分)
2、 编写一个字符界面的Java Application程序,接受用户输入的10个整数,比较并输出其中的最大值和最小值。(15分)
3、 理解并做答以下程序:(15分)
import java.util.*
class MyStack
{
private LinkedList ll=new LinkedList();
public void push(object o)
{
ll.addFirst(o);
}

public Object pop()
{
return ll.removeFirst();
}

public object query()
{
return ll.getFirst();
}

public boolean empty()
{
return ll.isEmpty();
}

public static void main(string[] args)
{
MyStack ms=new MyStack();
ms.push("one");
ms.push("two");
ms.push("three");
System.out.println(ms.pop());
System.out.println(ms.query());
System.out.println(ms.pop());
System.out.println(ms.empty());
}

}

请写出屏幕打印的数据
...全文
246 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenyifei211 2008-01-16
  • 打赏
  • 举报
回复
1,2题:
package test;

import java.util.Arrays;
import java.util.Scanner;

public class Output1 {

/**
* @param args
*/
public void outName(){
System.out.println("please input your name");
Scanner scan=new Scanner(System.in);
String username=scan.next();
System.out.println("welcome you :"+username);
}
public boolean outNumber(){
System.out.println("please input 10 integer");
Scanner scan=new Scanner(System.in);
int[] number=new int[10];
for(int i=0;i<10;i++){
if(scan.hasNextInt())
number[i]=scan.nextInt();
else{
System.out.println("input is not right");
return false;
}
}
Arrays.sort(number);
System.out.println("min number:"+number[0]);
System.out.println("max number:"+number[9]);
return true;
}
public static void main(String[] args) {
// TODO 自动生成方法存根
Output1 output=new Output1();
output.outName();
output.outNumber();
}

}

3题
three
two
two
false
是很简单
lixkyx 2008-01-16
  • 打赏
  • 举报
回复
呵呵,也未免太简单了吧!哪家公司会出这种小儿科的题目?
xiaowei_forsale 2008-01-16
  • 打赏
  • 举报
回复
最基础的东西 也是最主要的
L_Spring 2008-01-16
  • 打赏
  • 举报
回复
很好的作業
jy02179045 2008-01-16
  • 打赏
  • 举报
回复
这个我知道。这个是期末考试的题目。。。。
euroman 2008-01-14
  • 打赏
  • 举报
回复
上面t复杂度是O(n*log(n)) s复杂度是O(n)

最好是
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int count = 9;
max = Integer.MIN_VALUE;
min = Integer.MAX_VALUE;
while( count-- < 0){
String str = br.readLine();
int buf = Integer.valueOf(str);
if(buf > max) max = buf;
else if( buf < min ) min = buf;
}

这样空间复杂度会降低很多,而且时间复杂度也线性化
euroman 2008-01-14
  • 打赏
  • 举报
回复
2、
ArrayList<Integer> l = new ArrayList<Integer>();

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i < 10; i++) {
String str = br.readLine();
try {
l.add(Integer.parseInt(str));
} catch(Exception ex) {
System.exit(-1);
}
}
Arrays.sort(l);
System.out.println("min: " + l.get(0) + "max: " + l.get(l.size()-1));
fhqypm_126 2008-01-14
  • 打赏
  • 举报
回复
这更象是小学生问1加2是多少?
稍微会点就能写出来.
xiaxinhuo 2008-01-14
  • 打赏
  • 举报
回复
我觉得是老师留的作业吧 公司会出这样的面试题吗?值得商讨.
不懂编程 2008-01-14
  • 打赏
  • 举报
回复
2题,混点分吧

public static void main(String[] args) {
String s;
int max = 0;
int min = 0;
int in = 0;
try {
for(int i = 0; i < 10; i++){
System.out.println("Please input value : ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
s = br.readLine();
in = Integer.valueOf(s);
if(in > max){
max = in;
}

if(i == 0 || in < min){
min = in;
}
}
System.out.println("Max value : " + max);
System.out.println("Min value : " + min);
} catch (IOException e) {
e.printStackTrace();
}
}
cattallen 2008-01-14
  • 打赏
  • 举报
回复
我觉着挺简单的,比我笔试时候的题容易多了,我那问的都是EJB,spring,hibernate
还好蒙过去了,嘿嘿
cattallen 2008-01-14
  • 打赏
  • 举报
回复
3
three
two
two
false
IamHades 2008-01-14
  • 打赏
  • 举报
回复
强烈建议csdn发帖的时候也能eclipse一样可以代码提示,我写的好痛苦~``555555555
IamHades 2008-01-14
  • 打赏
  • 举报
回复
3、
three
two
false
IamHades 2008-01-14
  • 打赏
  • 举报
回复
2、
int[] number = new int[10];
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i < 10; i++) {
String str = br.readLine();
try {
number[i] = Integer.parseInt(str);
} catch(Exception ex) {
i = i - 1;
}
}

for(int i = 0; i < 10; i++) {
min = Math.min(min, number[i]);
max = math.max(max, number[i]);
}

System.out.println(min);
System.out.println(max);
IamHades 2008-01-14
  • 打赏
  • 举报
回复
1、
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
System.out.println("Welcome you, " + str + "!");
journeydj 2008-01-14
  • 打赏
  • 举报
回复
我是典型的eclipse患者,机器没环境,让楼下的写吧:)
journeydj 2008-01-14
  • 打赏
  • 举报
回复
......更像作业题,那家公司这么没水准。。。

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧