网站首页 > 文章中心 > 其它

java代码运行截图大全

作者:小编 更新时间:2023-09-06 17:19:11 浏览量:354人看过

求这道题的Java代码和运行截图

package?guxi.test;

import?java.util.ArrayList;

import?java.util.List;

public?class?Stu?{

public?static?void?main(String[]?args)?{

java代码运行截图大全-图1

ListStu?学校?=?new?ArrayListStu();

//?测试学生

学校.add(new?Stu("张三",?"No.1"));

for?(int?i?=?0;?i?学校.size();?i++)?{

Stu?stu?=?学校.get(i);

stu.上课();

}?else?{

stu.考试();

}

java代码运行截图大全-图2

stu.study();

private?static?int?学生人数;

private?String?学号;

private?String?姓名;

private?String?性别;

private?String?年龄;

private?String?专业;

private?String?电子邮箱;

private?String?QQ;

private?String?住址;

public?Stu(String?姓名,?String?学号)?{

this.姓名?=?姓名;

this.学号?=?学号;

学生人数++;

System.out.println(姓名?+?"?入学,学号:"?+?学号?+?"?当前学生人数:"?+?学生人数);

public?void?上课()?{

System.out.println(姓名?+?"?在上课");

public?void?考试()?{

System.out.println(姓名?+?"?在考试");

public?void?study()?{

System.out.println(姓名?+?",你要好好学习,天天向上");

public?String?get学号()?{

return?学号;

public?void?set学号(String?学号)?{

public?String?get姓名()?{

return?姓名;

public?void?set姓名(String?姓名)?{

public?String?get性别()?{

return?性别;

public?void?set性别(String?性别)?{

this.性别?=?性别;

public?String?get年龄()?{

return?年龄;

public?void?set年龄(String?年龄)?{

this.年龄?=?年龄;

public?String?get专业()?{

return?专业;

public?void?set专业(String?专业)?{

this.专业?=?专业;

public?String?get电子邮箱()?{

return?电子邮箱;

public?void?set电子邮箱(String?电子邮箱)?{

this.电子邮箱?=?电子邮箱;

public?String?getQQ()?{

return?QQ;

public?void?setQQ(String?qQ)?{

QQ?=?qQ;

public?String?get住址()?{

return?住址;

public?void?set住址(String?住址)?{

this.住址?=?住址;

public?static?int?get学生人数()?{

return?学生人数;

java 实现截图并且 保存在本地

import java.awt.AWTException;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Graphics;

import java.awt.GraphicsDevice;

import java.awt.GraphicsEnvironment;

import java.awt.Rectangle;

import java.awt.Robot;

import java.awt.Toolkit;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.awt.event.MouseMotionAdapter;

import java.awt.image.BufferedImage;

import java.awt.image.RescaleOp;

import java.io.File;

import java.io.IOException;

import java.text.SimpleDateFormat;

import java.util.Date;

import javax.imageio.ImageIO;

import javax.swing.JFrame;

import javax.swing.filechooser.FileSystemView;

/**

* java截屏

* 运行后将当前屏幕截取,并最大化显示.

* 拖拽鼠标,选择自己需要的部分.

* 按Esc键保存图片到桌面,并退出程序.

*

* @author JinCeon

*/

public class SnapshotTest {

public static void main(String[] args) {

// 全屏运行

RectD rd = new RectD();

GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment()

.getDefaultScreenDevice();

gd.setFullScreenWindow(rd);

class RectD extends JFrame {

private static final long serialVersionUID = 1L;

int orgx, orgy, endx, endy;

Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

BufferedImage image;

BufferedImage tempImage;

BufferedImage saveImage;

Graphics g;

@Override

public void paint(Graphics g) {

tempImage = ro.filter(image, null);

g.drawImage(tempImage, 0, 0, this);

public RectD() {

snapshot();

setVisible(true);

// setSize(d);//最大化窗口

setDefaultCloseOperation(EXIT_ON_CLOSE);

this.addMouseListener(new MouseAdapter() {

public void mousePressed(MouseEvent e) {

orgx = e.getX();

orgy = e.getY();

});

this.addMouseMotionListener(new MouseMotionAdapter() {

public void mouseDragged(MouseEvent e) {

endx = e.getX();

endy = e.getY();

g = getGraphics();

g.drawImage(tempImage, 0, 0, RectD.this);

int x = Math.min(orgx, endx);

int y = Math.min(orgy, endy);

int width = Math.abs(endx - orgx)+1;

int height = Math.abs(endy - orgy)+1;

// 加上1,防止width或height为0

g.setColor(Color.BLUE);

g.drawRect(x-1, y-1, width+1, height+1);

//减1,加1都是为了防止图片将矩形框覆盖掉

saveImage = image.getSubimage(x, y, width, height);

g.drawImage(saveImage, x, y, RectD.this);

this.addKeyListener(new KeyAdapter() {

public void keyReleased(KeyEvent e) {

// 按Esc键退出

saveToFile();

System.exit(0);

public void saveToFile() {

SimpleDateFormat sdf = new SimpleDateFormat("yyyymmddHHmmss");

String name = sdf.format(new Date());

File path = FileSystemView.getFileSystemView().getHomeDirectory();

String format = "jpg";

File f = new File(path + File.separator + name + "." + format);

try {

ImageIO.write(saveImage, format, f);

} catch (IOException e) {

e.printStackTrace();

public void snapshot() {

Robot robot = new Robot();

image = robot.createScreenCapture(new Rectangle(0, 0, d.width,

d.height));

} catch (AWTException e) {

Java入门编程题 求大佬帮忙解答一下 请附上代码和运行截图

public static void printMax(){

ListInteger list = new ArrayList();

for (int[] x:ay){

for (int y:x){

list.add(y);

System.out.println(Collections.max(list));

printMax();

求java基础编程和运行结果截图,程序代码最好做详细解释,万分感激

public class Test {//测试类

Student stu1 = new Student();

stu1.setAge(11);

stu1.setName("Zhang San");

stus[0] = stu1;

Postgraduate p1 = new Postgraduate();

p1.setName("Wang Wu");

p1.setStudydirection("Computer");

Undergraduate u1 = new Undergraduate();

u1.setName("Ma qi");

u1.setSpecialty("Maths");

for(int i = 0; i stus.length; i++){

stus[i].print();

System.out.println();

class Student {//学生类

private String name;

private int age;

public int getAge() {

return age;

public void setAge(int age) {

this.age = age;

public String getName() {

return name;

public void setName(String name) {

this.name = name;

public void print(){

System.out.println("name: " + name);

System.out.println("Age: " + age);

class Undergraduate extends Student {//本科生类

private String specialty;

public String getSpecialty() {

return specialty;

public void setSpecialty(String specialty) {

this.specialty = specialty;

super.print();

java代码运行截图大全-图3

System.out.println("specialty : " + specialty);

class Postgraduate extends Student {//研究生类Postgraduate

private String studydirection;

public String getStudydirection() {

return studydirection;

public void setStudydirection(String studydirection) {

this.studydirection = studydirection;

System.out.println("studydirection: " + studydirection);

----------------

name: Zhang San

Age: 11

name: Li Si

name: Wang Wu

studydirection: Computer

name: Ma qi

specialty : Maths

三道java编程题.求全部代码和执行截图.

public class JavaPractise {

JavaPractise o = new JavaPractise();

String subStr = o.getMaxLengthAddPart(str);

System.out.println(subStr);

String binaryFlow = "000011110000011111";

String sameSubStr = o.getMaxSameSubStr(binaryFlow);

System.out.println(sameSubStr);

String letterFlow = "aaBBBcCCCCddddddEEEE";

String sameLettersSubStr = o.getMaxSameLettersSubStr(letterFlow);

System.out.println(sameLettersSubStr);

* 校验字符串是否符合数字规范

* */

private boolean isNum(String str){

boolean result = true;

if(str.length() 1)

return false;

for(int i = 0 ; i str.length(); i ++){

return result;

private boolean isBinaryFlow(String binaryFlow){

if(binaryFlow.length() 1)

for(int i = 0 ; i binaryFlow.length(); i ++){

if(binaryFlow.charAt(i) != ?'0' ?binaryFlow.charAt(i) != '1')

private boolean isLetterFlow(String letterFlow){

if(letterFlow.length() 1)

for(int i = 0 ; i letterFlow.length(); i ++){

char cur = letterFlow.charAt(i);

if(!( ('z'= cur cur = 'a') || ('Z' = cur cur 'A') ) )

* 获取最长增长数字的子串

private String getMaxLengthAddPart(String str){

str = str.trim();

if(!isNum(str))

return "";

String temp = ""+str.charAt(0);

String maxSubStr = temp;

for(int i = 1; i str.length(); i++){

char curChar = str.charAt(i);

char lastChar = str.charAt(i-1);

if( curChar lastChar){

temp += curChar;

if(i != (str.length()-1))

continue;//如果当前节点为最后一个节点,那么强制进入下面环节,进行

maxSubStr = maxSubStr.length() temp.length() ? maxSubStr : temp;

temp = ""+curChar; //清空原数据,并从当前节点记录

return maxSubStr;

* 二进制流最长字符串判定

private String getMaxSameSubStr(String str){

if(!isBinaryFlow(str))

if( curChar == lastChar){

* 字符串的最长相同部分截取

private String getMaxSameLettersSubStr(String str){

if(!isLetterFlow(str))

运行结果如下:

以上就是土嘎嘎小编为大家整理的java代码运行截图大全相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章