Java常考编程题(基础)--不断更新
来源:互联网 发布:opencv2.4.4 sift算法 编辑:程序博客网 时间:2024/05/18 01:57
Java常考编程题(基础)--不断更新
1.题目:有1、2、3、4四个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
public class lianxi11 {
public static void main(String[] args) {
int count = 0;
for(int x=1; x<5; x++) {
for(int y=1; y<5; y++) {
for(int z=1; z<5; z++) {
if(x != y && y != z && x != z) {
count ++;
System.out.println(x*100 + y*10 + z );
}
}
}
}
System.out.println("共有" + count + "个三位数");
}
}
2.题目:输入三个整数x,y,z,请把这三个数由小到大输出。
import java.util.*;
public class lianxi15 {
public static void main(String[] args) {
input fnc = new input();
int x=0, y=0, z=0;
System.out.print("输入第一个数字:");
x = fnc.input();
System.out.print("输入第二个数字:");
y = fnc.input();
System.out.print("输入第三个数字:");
z = fnc.input();
if(x > y) {
int t = x;
x = y; y = t;
}
if(x > z) {
int t = x;
x = z; z = t;
}
if(y > z) {
int t = y;
y = z;
z = t;
}
System.out.println( "三个数字由小到大排列为: "+x + " " + y + " " + z);
}
}
class input{ public int input() {
int value = 0;
Scanner s = new Scanner(System.in);
value = s.nextInt();
return value;
}
}
3.题目:输出9*9口诀。
public class lianxi16 {
public static void main(String[] args) {
for(int i=1; i<10; i++) {
for(int j=1; j<=i; j++) {
System.out.print(j + "*" + i + "=" + j*i + " " );
if(j*i<10){System.out.print(" ");
}
}
System.out.println();
}
}
}
4.题目:对10个数进行排序
import java.util.*;
public class lianxi28 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int[] a = new int[10];
System.out.println("请输入10个整数:");
for(int i=0; i<10; i++) {
a[i] = s.nextInt();
}
for(int i=0; i<10; i++) {
for(int j=i+1; j<10; j++) {
if(a[i] > a[j]) {
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
for(int i=0; i<10; i++) {
System.out.print(a[i] + " ");
}
}
}
5.Java继承、多态面试题:
1.父类:
publicclassA {
publicint a = 0;
publicvoidfun(){
System.out.println("-----A-----");
}
}
子类:publicclassB extends A{
publicint a = 1;
publicvoidfun(){
System.out.println("-----B-----");
}
主方法:
publicstaticvoidmain(String[] args){
A classA =new B();
System.out.println(classA.a);
classA.fun();
}
}
2.父类:
public class Monkey{
public Monkey (String s)
{
System.out.println(s);
}
public void speak()
{
System.out.println("咿咿呀呀......");
}
}
子类:
public People extends Monkey {
public People() {}
public void speak()
{
System.out.println("小样的,不错嘛!会说话了!");
}
public void think()
{
System.out.println("别说话!认真思考!");
}
}
子类:
public class E{
public void main(String[] args) {
Monkey monkey = new Monkey("我是猴子");
monkey.speak();
People people = new People();
people.speak();
people.think();
}
}
- Java常考编程题(基础)--不断更新
- java常考概念题
- 常考的java数据库笔试题
- java常考笔试题1
- java常考笔试题2
- java常考笔试题3
- 黑马程序员 java 基础面试常考题目总结
- C语言常考基础考点(二)
- Java面试常考知识点
- Java笔试常考知识点
- Java面试常考题目
- Java笔试面试题二(常考问答)
- Java面试2018常考题目汇总(一)
- 数据结构编程题(不断更新)
- 数据库sql一些常考基础命令
- 操作系统和linux编程常考题目
- SQL常考笔试题
- 数据库常考笔试题
- git命令 branch 切换远程分支Github
- intellij IDEA 启动tomcat时显示端口被占用
- servlet3.0 getPart()与getParts()获取上传文件
- Redis 主从复制
- CSS 设置字体大小用法介绍
- Java常考编程题(基础)--不断更新
- Web项目中使用Spring 3.x + Quartz 2.x实现作业调度详解
- 让eclipse变得快点,取消validation
- ubantu下Eclipse输入中文vim显示乱码,vim中输入中文eclipse显示乱码
- Type Conversion in Expression Evaluation
- app与app间打开并传递参数
- MP3,aac,ac3,eac3
- 第十四周 OJ总结<1>--数组逆序
- 66. Plus One