java考试万能代码,java基础题目在线做题
急急急,求考试java编程代码。
public class Animal
古交网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、自适应网站建设等网站项目制作,到程序开发,运营维护。创新互联从2013年开始到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联。
{
// 动物名称 颜色 类别
private String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
private String color;
public String getColor()
{
return color;
}
private String type;
public String getType()
{
return type;
}
public void setType(String type)
{
this.type= type;
}
private String amlClass;
public String getAmlClass()
{
return amlClass;
}
public void setAmlClass(String amlClass)
{
this.amlClass = amlClass;
}
public String shout()
{
if (this.name.equals("兔子"))
{
return "叽叽叽";
}
else if (this.name.equals("青蛙"))
{
return "呱呱呱";
}
return ""; }
public String eat()
{
if (this.name.equals("兔子"))
{
return "胡萝卜";
}
else if (this.name.equals("青蛙"))
{
return "昆虫";
}
return ""; }
}
public interface SwimmingInter
{
String swimming();
}
public class Rabbit extends Animal
{
public Rabbit()
{
this.setName("美人");
this.setColor("黑色");
this.setAmlClass("哺乳类");
this.setType("兔子");
}
}
public class Frog extends Animal implements SwimmingInter
{
public Frog()
{
this.setName("大兵");
this.setColor("绿色");
this.setAmlClass("非哺乳类");
this.setType("青蛙");
}
public String swimming()
{
return "虽然不是鱼,但青蛙也是游泳高手";
}
}
main 函数
Frog frog = new Frog();
Rabbit rabbit = new Rabbit();
System.out.println("那只"+frog.getColor+",名叫"+forg.getName()+的+frog.getType());
// 这部分输出 就省略了 拼一下就好! 大部分手敲 所以直接拷过去可能有格式问题不能直接用! 照着敲一遍 应该就ok! 我小菜来的~ 不要分了~ 写错不要喷~
java考试,求编程题步骤!!!
题目一:
参考代码
import java.util.Scanner;
public class JiaFaDemo {
public static void main(String[] args) {
int x = (int) (Math.random() * 100);
int y = (int) (Math.random() * 100);
System.out.println(x+"+"+y+"="+(x+y));//自动答题 58+4=62
// System.out.print(x+"+"+y+"=");//人工输入答题 需要导入包import java.util.Scanner;
// Scanner input = new Scanner(System.in);
// int z = input.nextInt();
// if(z==(x+y)){
// System.out.println("回答正确");
// }else{
// System.out.println("回答错误");
// }
}
}
输出
58+4=62
题目二
public class JiShuDemo {
public static void main(String[] args) {
int sum = 0;
for (int i = 1; i = 50; i++) {
if(i%2!=0){//不能被2整除的数是奇数
sum+=i;
}
}
System.out.println("1~50间奇数和="+sum);
}
}
输出
1~50间奇数和=625
java代码帮忙注释下!O(∩_∩)O谢谢要考试了,不懂啊!可以的话每段后面注释下!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
/**
* 继承JFrame 实现 MouseMotionListener,ActionListener
*
*/
public class Exe10_1 extends JFrame implements MouseMotionListener,
ActionListener {
JLabel tracer;//声明一个JLabel
JButton start;//声明一个JButton
boolean tracing = true;// 定义一个Boolean变量
/**
* 构造函数
*/
public Exe10_1() {
super("鼠标跟踪");//设置JFrame的title
setBounds(300, 300, 300, 300); // JFrame大小
setLayout(new FlowLayout()); //JFrame的布局为FlowLayout
tracer = new JLabel();//给刚才声明的JLabel赋值
tracer.setPreferredSize(new Dimension(100, 30));//
tracer.setBackground(Color.blue);//设置背景色
tracer.setForeground(Color.white);//设置前景色
tracer.setOpaque(true);
addMouseMotionListener(this);//整个JFrame监听鼠标事件
add(tracer); //JFrame添加JLabel
start = new JButton("停止跟踪");//Jbutton初始化的名字为“停止跟随”
start.addActionListener(this);//JButton添加监听事件
add(start);//JFrame添加JLabel
setVisible(true);//JFrame的可见性
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//右上角的【关闭】按钮
}
/* (当按下鼠标 不放开时 滑动鼠标 JLabel上打印内容)
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
*/
public void mouseDragged(MouseEvent e) {
tracer.setText("(x,y) = (" + e.getX() + "," + e.getY() + ")");
}
/* (鼠标在JFrame上滑动时 JLabel上打印内容)
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
*/
public void mouseMoved(MouseEvent e) {
tracer.setText("(x,y) = (" + e.getX() + "," + e.getY() + ")");
}
/* (鼠标监听事件处理)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
if (tracing == true) {
removeMouseMotionListener(this);//JFrame移除监听鼠标事件
start.setText("继续跟踪");//JLabel重新设置Text
tracing = false;
} else {
addMouseMotionListener(this);//JFrame添加鼠标事件监听
start.setText("停止跟踪");//JLabel重新设置Text
tracing = true;
}
}
/** 程序入口
* @param args
*/
public static void main(String[] args) {
Exe10_1 frame = new Exe10_1();//生成一个Exe10_1的实例 实例名为:frame
}
}
希望对你有帮助
java例题代码
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Demo {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入密码:");
try{
String pass = in.readLine();
if(pass.length() 6 || pass.length() 4){
System.err.println("长度错误,密码长度必须是4-6位");
return;
}
int password = Integer.parseInt(pass);
System.out.println("信息合法");
}catch(Exception e){
System.err.println("错误,输入的密码必须为数字");
}
}
}
求简单java题代码
import java.util.Scanner;
public class Medcine
{
private String name;
private String brand;
private String specifications;
private String attending;
public Medcine ( String name, String brand, String specifications, String attending )
{
this.name = name;
this.brand = brand;
this.specifications = specifications;
this.attending = attending;
}
@Override
public String toString ()
{
return String.format ("%1$s %2$s %3$s %4$s", this.name, this.brand, this.specifications, this.attending);
}
public static void main ( String[] args )
{
int count = 5;
Medcine[] medcines = new Medcine[5];
Scanner scanner = new Scanner (System.in);
System.out.println ("输入" + count + "组数据: ");
for ( int i = 0; i count; i++ )
{
String line = scanner.nextLine ().trim ();
String[] data = line.split ("\\s+");
Medcine medcine = new Medcine (data[0], data[1], data[2], data[3]);
medcines[i] = medcine;
}
scanner.close ();
for ( Medcine medcine : medcines )
{
System.out.println (medcine.toString ());
}
}
}
java编程代码,要完整的代码,可以运行出来的。谢谢!
Course.java
public class Course {
private String name;//课程名
private String id; //编号
private String selectId; //选修课编号
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSelectId() {
return selectId;
}
public void setSelectId(String selectId) {
this.selectId = selectId;
}
}
网站栏目:java考试万能代码,java基础题目在线做题
网页网址:http://ybzwz.com/article/hchddi.html