java代码运行截图大全,java代码运行截图大全

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

package guxi.test;

成都创新互联专业为企业提供源汇网站建设、源汇做网站、源汇网站设计、源汇网站制作等企业网站建设、网页设计与制作、源汇企业网站模板建站服务,十多年源汇做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

import java.util.ArrayList;

import java.util.List;

public class Stu {

public static void main(String[] args) {

ListStu 学校 = new ArrayListStu();

// 测试学生

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

学校.add(new Stu("李四", "No.2"));

学校.add(new Stu("王五", "No.3"));

学校.add(new Stu("赵六", "No.4"));

学校.add(new Stu("孙七", "No.5"));

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

Stu stu = 学校.get(i);

if (i % 2 == 0) {

stu.上课();

} else {

stu.考试();

}

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 学号) {

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 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) {

RescaleOp ro = new RescaleOp(0.8f, 0, null);

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() {

@Override

public void keyReleased(KeyEvent e) {

// 按Esc键退出

if (e.getKeyCode() == 27) {

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() {

try {

Robot robot = new Robot();

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

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

d.height));

} catch (AWTException e) {

e.printStackTrace();

}

}

}

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

public static void printMax(){

int[][] ay = {{22,91,0,5},{33,21},{19,-1,28,88}};

ListInteger list = new ArrayList();

for (int[] x:ay){

for (int y:x){

list.add(y);

}

}

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

}

public static void main(String[] args) {

printMax();

}

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

public class Test {//测试类

public static void main(String[] args) {

Student[] stus = new Student[5];

Student stu1 = new Student();

stu1.setAge(11);

stu1.setName("Zhang San");

stus[0] = stu1;

Student stu2 = new Student();

stu2.setAge(22);

stu2.setName("Li Si");

stus[1] = stu2;

Postgraduate p1 = new Postgraduate();

p1.setAge(33);

p1.setName("Wang Wu");

p1.setStudydirection("Computer");

stus[2] = p1;

Postgraduate p2 = new Postgraduate();

p2.setAge(44);

p2.setName("Zhao Liu");

p2.setStudydirection("English");

stus[3] = p1;

Undergraduate u1 = new Undergraduate();

u1.setAge(55);

u1.setName("Ma qi");

u1.setSpecialty("Maths");

stus[4] = u1;

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;

}

public void print(){

super.print();

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;

}

public void print(){

super.print();

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

}

}

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

name: Zhang San

Age: 11

name: Li Si

Age: 22

name: Wang Wu

Age: 33

studydirection: Computer

name: Wang Wu

Age: 33

studydirection: Computer

name: Ma qi

Age: 55

specialty : Maths

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

public class JavaPractise {

public static void main(String[] args) {

JavaPractise o = new JavaPractise();

String str = "1342973451345";

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 ++){

if(str.charAt(i) '0' ||  str.charAt(i) '9')

return false;

}

return result;

}

private boolean isBinaryFlow(String binaryFlow){

boolean result = true;

if(binaryFlow.length() 1)

return false;

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

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

return false;

}

return result;

}

private boolean isLetterFlow(String letterFlow){

boolean result = true;

if(letterFlow.length() 1)

return false;

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

char cur = letterFlow.charAt(i);

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

return false;

}

return result;

}

/**

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

* */

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){

str = str.trim();

if(!isBinaryFlow(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 getMaxSameLettersSubStr(String str){

str = str.trim();

if(!isLetterFlow(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;

}

}

运行结果如下:


新闻名称:java代码运行截图大全,java代码运行截图大全
浏览路径:http://pwwzsj.com/article/heioeg.html