count=1
for (int i = 0;i count;i++) {
temp += a ;
}
这里面涉及到了字符串和整数之间的转换.
temp += a ;即把字符串temp末尾加上a(这里面会自动把整数型的数据a转换为字符串)
Integer.parseInt(temp) ;即将字符创temp转换为整数型.
不知道我说的是否清楚
输入一整型数值给Vertices,
提示重新输入且应输入
退出程序
}else{
生成一个Vertices * Vertices 大小的数组Graph,
填充数组 :行号与列号相同填充0,其余填充10以内随机数
交换元素:以[i][j]位置的数值与[j][i]位置的数值互换
最后打印数组各元素
class NoLowerLetterException extends Exception {
public NoLowerLetterException(String msg) {
super(msg);
class NoDigitException extends Exception {
public NoDigitException(String msg) {
class People {
void printLetter(char c) {
if (c = 'a' c = 'z') {
System.out.println(c);
} else {
try {
throw new NoLowerLetterException(String.valueOf(c));
} catch (NoLowerLetterException e) {
e.printStackTrace();
void printDigit(char c) {
throw new NoDigitException(String.valueOf(c));
} catch (NoDigitException e) {
public class ExceptionExample {
public static void main(String args[]) {
People people = new People();
// //将i转换为char类型,执行people.printLetter()方法,如果出现异常则捕获,并输出异常的错误信息!
people.printLetter((char) i);
// ()方法,如果出现异常则捕获,并输出异常的错误信息!
people.printDigit((char) i);
代码如下,望采纳
public?class?PrintPrime{
public?static?void?main(String?args[]){
//设置一个计数变量count,用于统计一行当中已经输出数字的个数
int?count?=?0;
//判断数字是否为素数,若是,则count+1并输出数字
if(PrintPrime.IsPrime(i)){
count++;
System.out.print(i+"?");
//如果一行十个已经输出完毕,计数归零,换行
if(count==10){
count=0;
System.out.println();
//判断数字是否为素数
public?static?boolean?IsPrime(int?n){
//如果小于等于三,则大于一即为素数
return?n?1;
if(n%i?==?0)
return?false;
return?true;
自己纯手打,老半天才弄出来啊
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.util.Random;
import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
// 初始化所有组件
lb1 = new JLabel("欢迎使用人机猜拳程序");
ta1 = new JTextField();
b1 = new JButton("剪刀");
p1 = new JPanel();
// 设置第一个面板内容
Box box = Box.createVerticalBox();
Box box1 = Box.createHorizontalBox();
box1.add(ta1);
box.add(lb1);
box.add(box1);
box.add(Box.createVerticalStrut(10));
box.add(new JLabel());
p1.add(box);
// 设置第二个面板
b1.addActionListener(new buttonAction());
this.getContentPane().add(p1);
this.setTitle("机器人猜拳游戏");
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//事件类
class buttonAction extends AbstractAction{
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b1){
ta1.setText("剪刀");
init(ta1.getText());
ta1.setText("石头");
ta1.setText("布");
public String getQuan(){
String str="";
if(num==0){
str="剪刀";
}else if(num==1){
str="石头";
str="布";
return str;
// 判断输赢方法
String s="";
s="平局";
s="你赢";
s="电脑赢";
return s;
public void init(String wo){
String sy=""; // 保存输赢结果
String dncq=getQuan(); //电脑出拳
if(wo.equals(dncq)){
sy="平局";
}else if(wo.equals("剪刀")dncq.equals("布")){
sy="你赢";
}else if(wo.equals("石头")dncq.equals("剪刀")){
}else if(wo.equals("布")dncq.equals("石头")){
sy="电脑赢";
public static void main(String[] args) {
以上就是土嘎嘎小编为大家整理的java吐舌代码的简单介绍java吐舌代码的简单介绍相关咨询咨询主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!