包含Javaascent的词条

博主:adminadmin 2022-12-30 09:00:07 873

今天给各位分享Javaascent的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

编写JAVA类,实现打印数组中出现次数最多元素

package com.ascent.test;

public class TestArrayInt {

public static void main(String[] args) {

int a[]={1,2,3,1,3,2,5,6,4,7,8,9,1,2,5,3,2,1,3,2,3};//举例用的数组!

int j=1,max=0,min=0,c=0,x=0; //j表示元素在数组中出现的次数,max,min表示就记录次数,c,x存储次数最多的元素下标!!

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

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

if(a[i]==a[ii])

j++;

}

if(jmax){

max=j;

c=i;

}else if(j==max){

x=i;

min=j;

}

j=1;

}

if(max==min)

System.out.println("出现次数最多的元素是:"+a[c]+"\t"+a[x]+"\t次数为:"+max);

else

System.out.println("出现次数最多的元素是:"+a[c]+"\t次数为:"+max);

}

}

//这个程序也就最多2个元素 如果想要更多的你可以用个数组搞定!!

java getAscent()有什么用

getAscent()是FontMetrics中的一个方法,它返回某字体的基线(baseline)到该字体中大多数字符的升部(ascender)之间的距离。一个字体中存在着很多假想的“线”,它们决定了该字体文字的显示效果。借用一幅图片说明:

基线(baseline)

大写字母H或小写字母n底部所踩的那条假想的线。O、V、W等字母底部会特地稍微超过基线一些,为了能在视觉上与基线持平。

大写字高(cap height)

H或E等直线型大写字母从基线到字母顶部额的高度。H或E等顶部对齐线叫做大写线(cap line)。

类似地,O、A等字母的顶部会超过大写线一些。

x字高(x-height)

为了称呼小写字母的高度,用没有上下延伸部分的x作为小写字母的代表,将其高度命名为x字高。

升部(ascender)

小写字母h、d、f等从x字高向上延伸的部分,叫做升部,其高度叫做升部高。

多数罗马正体中,升部线比大写线高一些。

降部(descender)

小写字母从基线向下延伸的部分。

getAscent返回的就是baseline到ascender之间的距离。相应地getDescent返回的则是baseline到descender之间的距离。

求一个关于Java的例子

public abstract class FontMetrics

extends Object

implements Serializable

FontMetrics 类定义字体规格对象,该对象封装将在特定屏幕上呈现特定字体的有关信息。

由于当中很多方法都形成关闭的、相互递归的循环,所以必须注意,在每个这样的循环中至少要实现其中一个方法,以防止在使用子类时产生无穷递归。特别建议,至少要重写以下方法集合以确保正确性,并防止无穷递归(虽然其他子集也可以)。

getAscent()

getLeading()

getMaxAdvance()

charWidth(char)

charsWidth(char[],

int, int)

注意,这些方法的实现效率低下,因此通常利用更高效的特定于工具包的实现重写它们。

当应用程序要求将字符放置在 (x, y)

位置时,放置字符的方式是使其引用点(附图中显示的点)放置在该位置。引用点指定一条水平线,称为字符的基线

(baseline)。在正常的打印中,字符的基线应该对齐。

此外,字体中的每个字符都具有 ascent、descent 和 advance width 属性。ascent

是字符超出基线之上的距离。descent 是字符超出基线以下的距离。advance width 指示 AWT 应该放置下一个字符的位置。

字符数组或字符串也可以具有 ascent、descent 和 advance width 属性。数组的 ascent 是数组中所有字符的最大

ascent。descent 是数组中所有字符的最大 descent。advance width 是字符数组中每个字符的 advance width

之和。String 的 advance 是 String 沿基线的距离。此距离是

String 居中或右对齐应该使用的 width。

注意,String 的 advance 不一定是每个字符单独测量的 advance 之和,因为字符的 width

可随上下文变动。例如,在 Arabic

文本中,可以更改一个字符的形状,以连接到其他字符。而在有些脚本中,某些字符序列可以由单个形状(称为连字)表示。单独测量的字符并不能说明这些转换。

字体规格是基线相关的,意味着它们通常是独立应用于该字体的循环(模可能的网格提示作用)。

java用冒泡的思想,判断数组是否单调?

boolean isMono=true;

String type = "";

for(int i=0; isize; i++){

for(int j=i; jsize; j++){

if(array[i]array[j]){

if(type = "descent"){

isMono = false;

}

type= "ascent";

}else{

if(type = "ascent"){

isMono = false;

}

type = "descent";

}

}

}

return isMono;

java 如何实现即时监控内存

在 \jdk1.6.0_10\demo\management\MemoryMonitor 下得示例程序,可以去学习哈

import java.awt.*;

import java.awt.event.*;

import java.awt.image.BufferedImage;

import java.awt.geom.Line2D;

import java.awt.geom.Rectangle2D;

import java.util.Date;

import javax.swing.*;

import javax.swing.border.EtchedBorder;

import javax.swing.border.TitledBorder;

import java.lang.management.*;

import java.util.*;

public class MemoryMonitor extends JPanel {

static JCheckBox dateStampCB = new JCheckBox("Output Date Stamp");

public Surface surf;

JPanel controls;

boolean doControls;

JTextField tf;

// Get memory pools.

static java.util.ListMemoryPoolMXBean mpools =

ManagementFactory.getMemoryPoolMXBeans();

// Total number of memory pools.

static int numPools = mpools.size();

public MemoryMonitor() {

setLayout(new BorderLayout());

setBorder(new TitledBorder(new EtchedBorder(), "Memory Monitor"));

add(surf = new Surface());

controls = new JPanel();

controls.setPreferredSize(new Dimension(135,80));

Font font = new Font("serif", Font.PLAIN, 10);

JLabel label = new JLabel("Sample Rate");

label.setFont(font);

label.setForeground(Color.red);

controls.add(label);

tf = new JTextField("1000");

tf.setPreferredSize(new Dimension(45,20));

controls.add(tf);

controls.add(label = new JLabel("ms"));

label.setFont(font);

label.setForeground(Color.red);

controls.add(dateStampCB);

dateStampCB.setFont(font);

addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

removeAll();

if ((doControls = !doControls)) {

surf.stop();

add(controls);

} else {

try {

surf.sleepAmount = Long.parseLong(tf.getText().trim());

} catch (Exception ex) {}

surf.start();

add(surf);

}

validate();

repaint();

}

});

}

public class Surface extends JPanel implements Runnable {

public Thread thread;

public long sleepAmount = 1000;

public int usageHistCount = 20000;

private int w, h;

private BufferedImage bimg;

private Graphics2D big;

private Font font = new Font("Times New Roman", Font.PLAIN, 11);

private int columnInc;

private float usedMem[][];

private int ptNum[];

private int ascent, descent;

private Rectangle graphOutlineRect = new Rectangle();

private Rectangle2D mfRect = new Rectangle2D.Float();

private Rectangle2D muRect = new Rectangle2D.Float();

private Line2D graphLine = new Line2D.Float();

private Color graphColor = new Color(46, 139, 87);

private Color mfColor = new Color(0, 100, 0);

private String usedStr;

public Surface() {

setBackground(Color.black);

addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

if (thread == null) start(); else stop();

}

后面还有很多代码没贴出来 自己到JDK 的demo目录下查看吧

Javaascent的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、Javaascent的信息别忘了在本站进行查找喔。