public class Bird
{
private static int id = 0;
private String kind;
public Bird(String requiredKind)
{
id = id + 1;
kind = requiredKind;
}
public String toString()
{
return "Kind: " + kind + ", Id: " + id + "; ";
}
public static void main(String [] args)
{
Bird [] birds = new Bird[2];
birds[0] = new Bird("falcon");
birds[1] = new Bird("eagle");
for (int i = 0; i < 2; i++)
System.out.print(birds[i]);
System.out.println();
}
}
Run Code Online (Sandbox Code Playgroud)
为什么这会回来 …
如何使用重复来命名Java中的对象?我想创建52个这样的对象(卡片)
Card1
Card2
...
Card52
Run Code Online (Sandbox Code Playgroud)
我在想这样的事情
int i=1;
while (i<=52){
Card Card<i> = new Card();
i=i+1;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它发挥作用?
不是三元运算符假设像arg一样工作?真假 ???所以如果持续时间和石油超过规定的数量而不是字段变量,它应该返回true ..但是这会返回false
public class test12 {
int duration = 260;
int petroleum = 300;
boolean result;
public void checktrain(){
boolean result = duration>=250 && petroleum>=235? true : false;
this.result = result;
}
public void run(){
System.out.print(result);
}
public static void main(String args[]){
test12 tr = new test12();
tr.run();
}
}
Run Code Online (Sandbox Code Playgroud) 这是我得到的错误......
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at Maze.Map.readFile(Map.java:60)
at Maze.Map.<init>(Map.java:23)
at Maze.Board.<init>(Board.java:16)
at Maze.Maze.<init>(Maze.java:15)
at Maze.Maze.main(Maze.java:9)
Run Code Online (Sandbox Code Playgroud)
以下是我的代码!
package Maze;
import javax.swing.*;
public class Maze
{
public static void main(String[] args)
{
new Maze();
}
public Maze()
{
JFrame f = new JFrame();
f.setTitle("Maze Game");
f.add(new Board());
f.setSize(464, 485);
f.setLocationRelativeTo(null);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Run Code Online (Sandbox Code Playgroud)
package Maze;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Board extends JPanel implements ActionListener
{
private Timer timer;
private Map …
Run Code Online (Sandbox Code Playgroud) 它达到了必须打印线的程度System.out.printf("%4s%22s%24s\n","Year"...)
,然后在没有打印的情况下停止.
public class WorldPopulationGrowth {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner( System.in);
long BasePopulation; //The base, or current population
double GrowthRate; //The rate of increase
double GrowthResult; // The pop after growth rate increase
//Time to obtain the numbers needed for Calculation
//Specifically, the growth rate and the base population
System.out.println("Welcome to the world population calculator");
System.out.print("Enter the current world population:");
BasePopulation = input.nextLong();
System.out.println("Enter the current growth …
Run Code Online (Sandbox Code Playgroud) 我的java应用程序收到此错误.我相信故障是我的数组列表的添加功能.有没有更好的方法来融入这个想法而不会过于复杂?(java的第一周)非常感谢!
import java.util.ArrayList;
import java.util.Scanner;
public class PrimeSieve {
public static void main(int[] args) {
System.out.println("Enter the max integer(N value): ");
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
System.out.println("Compute prime numbers from 2 to: " + num);
if(num < 2){
System.out.println("N must be greater than or equal to 2.");
}
else if(num == 2) {
System.out.println("Prime numbers: 2");
}
else {
ArrayList<Integer> myArr = new ArrayList<Integer>();
int i = 2;
while(i <= num){
myArr.add(i);
}
System.out.println(myArr);
}
} …
Run Code Online (Sandbox Code Playgroud) 我不确定如何在Java语言中输出以下内容.注意输出中存在双短划线:
String keyName = projectId.AsString + "-comments-" + creationMomentString + "-" + _rand.nextInt() + ".txt";
System.out.println(creationMomentString);
System.out.println(_rand.getClass());
System.out.println(keyName);
Run Code Online (Sandbox Code Playgroud)
输出:
0000001466400377645
class java.security.SecureRandom
o7grn3qt-comments-0000001466400377645--874329600.txt
-------------------------------------^
Run Code Online (Sandbox Code Playgroud) 给定"The brown fox jumped the fence jumped. The jumped fox? The fox. Jumped"
通过空格分割的句子在数组中显示空字符串.我期待带有标点符号的单词或单词.这句空字符从哪里来的?