1,Java 心形图形我不清楚你要打出来的是什么图形 , 但是至少那些j--和k--的循环,判断条件肯定是>= 才对当然这么改了以后,输出的图形不一定是你要的,逻辑需要仔细验证public class Heartpublic static void main(String[] args)int size = 4;int number = 7;for (int i = 0; i <= size; i++)for (int j = 4; j <= 4 - i; j--)//变量j一直自减1 最后是负数的时候也满足条件 所以无限循环了System.out.print(" ");for (int j = 1; j <= i; j++)//System.out.print("*");for (int j = size; j <= size - i; j--)//变量j一直自减1 最后是负数的时候也满足条件 所以无限循环了System.out.print(" ");for (int j = 1; j <= i; j++)System.out.print("*");System.out.println();}for (int k = number; k <= number; k--)System.out.print("*");System.out.println();} }}用两个圆就可以做了的. flash可以画图的``就是没有ps这么发达``` 这招是我刚学flash时做的``很简单`而且受用哦``` 先画一个正方形``然后利用这个正方形的边长为直径`画两个圆形`(查不太多也无所谓`只是个人觉得这样好看)` 然后`把正方形`旋转45度``搞成一个大家印象中的菱形的姿势(就是一个脚着地的那种)``然后把`两个圆放到正方形上边的两个边上`最好是让直径和正方形的边重合``就好了``` ps:最好都是用实心的`如果只用带边的那种`画完了里面会有线的`还要再擦``【java爱心代码公式,Java 心形图形】
2,如何用java中的for输出心形public class Teststatic float count(float x, float y)return (float) (Math.pow((x * x + y * y - 1), 3) - x * x * y * y * y); } public static void printEmpty()int height = 50, width = 100;int heart[][] = new int[height][width];float hx = 0.0f, hy = 0.0f;for (int y = height / 2; y > -height / 2; y--)for (int x = -width / 2; x < width / 2; x++)hx = (float) x / (float) (width / 2.8f);hy = (float) (y) / (float) (height / 2.8f);if (count(hx, hy) <= 0.0f)heart[height / 2 - y][x + width / 2] = 1;}}}for (int y = 1; y < height - 1; y++)for (int x = 1; x < width - 1; x++)if (heart[y][x] == 1&& !(heart[y][x - 2] == 1 && heart[y][x + 2] == 1&& heart[y - 1][x] == 1 && heart[y + 1][x] == 1))System.out.print("*");} elseSystem.out.print(" ");}}System.out.println();}System.out.println(); } public static void main(String[] args)printEmpty(); }}
3,Java打印心形图形的算法我不清楚你要打出来的是什么图形,但是至少那些j--和k--的循环,判断条件肯定是>= 才对当然这么改了以后,输出的图形不一定是你要的 , 逻辑需要仔细验证import java.util.Scanner;public class Test static void draw(int n)int i, j;for (i = 1 - (n >> 1); i <= n; i++)if (i > 0)for (j = 0; j < i; j++)System.out.print("");for (j = 1; j <= 2 * (n - i) + 1; j++)if (j == 1 || j == 2 * (n - i) + 1)System.out.print(" *");elseSystem.out.print("");System.out.println("\n");} else if (i == 0)System.out.print(" *");for (j = 1; j < n; j++)System.out.print("");System.out.print(" *");for (j = 1; j < n; j++)System.out.print("");System.out.print(" *\n");} elsefor (j = i; j < 0; j++)System.out.print("");for (j = 1; j <= n + 2 * i + 1; j++)if (i == 1 - (n >> 1))System.out.print(" *");else if (j == 1 || j == n + 2 * i + 1)System.out.print(" *");elseSystem.out.print("");for (j = 1; j <= -1 - 2 * i; j++)System.out.print("");for (j = 1; j <= n + 2 * i + 1; j++)if (i == 1 - (n >> 1))System.out.print(" *");else if (j == 1 || j == n + 2 * i + 1)System.out.print(" *");elseSystem.out.print("");System.out.print("\n");}}public static void main(String[] args)System.out.println("Please input the size (n>=4):");Scanner sc = new Scanner(System.in);int n = sc.nextInt();draw(n);} }
4 , 求一份爱心形状特征提取Copencv的代码1、opencv由一系列 c 函数和少量 c++ 类构成,同时提供了python、ruby、matlab等语言的接口,用类来组织,基本是c 。2、opencv2.0以后增加了对c++风格代码的兼容 。vs2008+opencv2.1,所有的函数他都是有的,可以直接调用 。整个项目的结构图:编写DetectFaceDemo.java,代码如下:[java] view plaincopyprint?package com.njupt.zhb.test;import org.opencv.core.Core;import org.opencv.core.Mat;import org.opencv.core.MatOfRect;import org.opencv.core.Point;import org.opencv.core.Rect;import org.opencv.core.Scalar;import org.opencv.highgui.Highgui;import org.opencv.objdetect.CascadeClassifier;// // Detects faces in an image, draws boxes around them, and writes the results // to "faceDetection.png". //public class DetectFaceDemopublic void run()System.out.println("\nRunning DetectFaceDemo");System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());// Create a face detector from the cascade file in the resources // directory. //CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath()); //Mat image = Highgui.imread(getClass().getResource("lena.png").getPath()); //注意:源程序的路径会多打印一个/,因此总是出现如下错误/** Detected 0 faces Writing faceDetection.png libpng warning: Image* width is zero in IHDR libpng warning: Image height is zero in IHDR* libpng error: Invalid IHDR data*///因此,我们将第一个字符去掉 String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));// Detect faces in the image. // MatOfRect is a special container class for Rect. MatOfRect faceDetections = new MatOfRect();faceDetector.detectMultiScale(image, faceDetections);System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));// Draw a bounding box around each face. for (Rect rect : faceDetections.toArray())Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));}// Save the visualized detection. String filename = "faceDetection.png";System.out.println(String.format("Writing %s", filename));Highgui.imwrite(filename, image);}}package com.njupt.zhb.test;import org.opencv.core.Core;import org.opencv.core.Mat;import org.opencv.core.MatOfRect;import org.opencv.core.Point;import org.opencv.core.Rect;import org.opencv.core.Scalar;import org.opencv.highgui.Highgui;import org.opencv.objdetect.CascadeClassifier;//// Detects faces in an image, draws boxes around them, and writes the results// to "faceDetection.png".//public class DetectFaceDemopublic void run()System.out.println("\nRunning DetectFaceDemo");System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());// Create a face detector from the cascade file in the resources// directory.//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());//注意:源程序的路径会多打印一个/,因此总是出现如下错误/** Detected 0 faces Writing faceDetection.png libpng warning: Image* width is zero in IHDR libpng warning: Image height is zero in IHDR* libpng error: Invalid IHDR data*///因此,我们将第一个字符去掉String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));// Detect faces in the image.// MatOfRect is a special container class for Rect.MatOfRect faceDetections = new MatOfRect();faceDetector.detectMultiScale(image, faceDetections);System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));// Draw a bounding box around each face.for (Rect rect : faceDetections.toArray())Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));}// Save the visualized detection.String filename = "faceDetection.png";System.out.println(String.format("Writing %s", filename));Highgui.imwrite(filename, image); }}3.编写测试类:[java] view plaincopyprint?package com.njupt.zhb.test;public class TestMainpublic static void main(String[] args)System.out.println("Hello, OpenCV");// Load the native library. System.loadLibrary("opencv_java246");new DetectFaceDemo().run();}}//运行结果://Hello, OpenCV ////Running DetectFaceDemo ///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml //Detected 8 faces //Writing faceDetection.pngpackage com.njupt.zhb.test;public class TestMainpublic static void main(String[] args)System.out.println("Hello, OpenCV");// Load the native library.System.loadLibrary("opencv_java246");new DetectFaceDemo().run(); }}//运行结果://Hello, OpenCV////Running DetectFaceDemo///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml//Detected 8 faces//Writing faceDetection.png
推荐阅读
- 大型游戏排行榜前十名,我想知道现在大型网络游戏排行前十那个人气最高最受欢迎最好玩
- android镜像下载,安装的adtbundle中的sdk manager中没有可以下载的支持android系统
- mind系列,mind的语法全部全部初二下学期的mind语法和用法
- ios开发培训课程有哪些软件,ios培训课程有哪些 关键课程有哪些
- 用于编程代码的软件有哪些名字,用什么软件可以编程
- 手机连接不上服务器怎么办? 手机无法找到服务器怎么办
- 苹果6ios13怎么下载,苹果6如何下载软件
- ai开发工程师好找工作吗,在东莞ai工程师好找吗
- 三菱plc模拟量编程实例详解,三菱PLC如何用FROM和TO处理模拟量