小编Eng*_*uad的帖子

Java中用于C#格式化字符串cout的等效语句

以下语句的Java等效指令是什么:

String name;
cout << "So your name is  " << name << endl;  
Run Code Online (Sandbox Code Playgroud)

或者在C#中

console.writeline("So your name is {0} ", name);
Run Code Online (Sandbox Code Playgroud)

c# java

0
推荐指数
1
解决办法
9558
查看次数

意外类型需要变量找到值

public class example
{
    public ArrayList<Integer> ToFill = new ArrayList<>();

    public void Alter(int Value , int Position)
    { 
      ToFill.get(Position) = Value ;  // this line has an error 
    }
}
Run Code Online (Sandbox Code Playgroud)

由于某种原因,这段代码给出了编译错误,有人可以解释原因吗?

java arraylist

0
推荐指数
1
解决办法
1万
查看次数

按行选择编辑jtable内容

我有一个具有Editbutton的类并将其设置为actionListener.我写了我的全班代码.

我有3班,

public class UserPage extends JFrame implements ActionListener {

private AllUser userModel;
private JTable uTable;
JButton editButton;

public UserPage() {
    setTitle("All User Information");
    userModel = new AllUser();
    uTable = new JTable(userModel);
    add(new JScrollPane(uTable), BorderLayout.CENTER);
    add(buttonPanels(), BorderLayout.PAGE_START);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(800, 600);
    this.setLocation(300, 60);
}

public final JPanel buttonPanels() {
    JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));

    editButton=new JButton("Edit");

    editButton.addActionListener(this);

    buttonsPanel.add(editButton);

    return buttonsPanel;
}

@Override
public void actionPerformed(ActionEvent e) {
    if(e.getSource()== editButton){
        int selectedRow=uTable.getSelectedRow();
        if(selectedRow>0){
            editUser(selectedRow);

        }
        else{
            JOptionPane.showMessageDialog(null, "Select a row");
        } …
Run Code Online (Sandbox Code Playgroud)

java swing jpanel jframe jtextfield

0
推荐指数
1
解决办法
252
查看次数

编写一种方法,以24小时格式(1430)和12小时格式(下午2:30)返回时间

所以,我正在尝试使用SimpleDateFormat来获取用户输入,但我不断收到错误,线程"main"中的异常java.lang.IllegalArgumentException:无法将给定的对象格式化为日期

我不确定如何获取字符串来获取信息并转换它,或者是否可以这样做.任何能引导我朝正确方向发展的评论都将非常感激.

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class takeTime {


    public static void main(String[] args) {


        Scanner reader = new Scanner(System.in);

        System.out.print( "Please enter a time: " );
        String now = reader.nextLine();
        SimpleDateFormat format = new SimpleDateFormat("h:mm a");
        System.out.println( format.format(now));
    }

}
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
393
查看次数

使用多个线程递增和递减单个共享变量

当递增和使用一个单一的共享变量递减多线程,我怎么能保证线程在syncronized方式计算,不跳过任何价值.

我创建了一个单独的类,其中有3个不同的方法,一个用于递增,另一个用于递减,最后一个用于返回值.它们都是同步的.

结果显示了一个例子:

  • 这是Thread_4迭代:-108 of 500
    这是Thread_5迭代:291 of 500
    这是Thread_4迭代:-109 of 500
    这是Thread_4迭代:-110 of 500

正如您所看到的那样,线程正在递减,但随后它会跳转到"291",这不应该发生,因为我使用的是共享变量.

*******************编辑********

代码: - 共享变量类

public class shareVar extends Thread
{
    private static int sharedVariable = 0;


    public synchronized static void increment(){
        sharedVariable++;
    }

    public synchronized static void decrement(){
        sharedVariable--;
    }

    public  static int value(){
        return sharedVariable;
    }
}
Run Code Online (Sandbox Code Playgroud)

-----递增类

sVar incrementVal = new sVar();

public synchronized void display(){

    for(int …
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading bluej

0
推荐指数
1
解决办法
1万
查看次数

如何在jtextfield中键入阿拉伯语文本

有人请帮我完成我的项目.我的java项目中有文本字段,我想用阿拉伯语输入学生的详细信息.我尝试了很多来源,但他们没有用.我知道文本字段支持阿拉伯语输入,因为我在oracle文档中看到了它.请有人帮帮我..

java swing input arabic jtextfield

0
推荐指数
1
解决办法
624
查看次数

cmd java无法正常工作

我目前正在学习Java并使用我的命令提示符作为编译器.但每次我执行java命令后跟我的测试类"Hello",我得到以下错误消息:

Exception in thread "main" java.lang.NoClassDefFoundError: Hello (wrong name: hello/Hello)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Run Code Online (Sandbox Code Playgroud)

现在我检查了我的"CLASSPATH"环境变量,它是正确的,如下所示:.; C:\ Program Files\Java\jdk1.7.0_25\bin; 我甚至试过删除.从CLASSPATH开始,但它没有做任何不同的事情.现在我的javac命令可以通过创建.java类的.class版本来正常工作.但我真的无法让它实际执行java命令.

我的类的名字是Hello,所以我输入了javac Hello.java来将我的文件编译为类文件并且它有效.但是当我输入:java Hello是我收到上述错误消息的时候.我已经在我创建的NetBeans IDE上测试了该程序,它完美无缺,没有任何错误.

有什么可能会阻止我执行我的java命令来运行.class文件?

java classpath

0
推荐指数
1
解决办法
193
查看次数

哪一种更适合游戏开发?Jpanel还是jframe?

我正在尝试使用 java jframe 开发游戏。事件/图形的每件事都做得非常好。但是当我尝试在 jFrame 中添加按钮、菜单等时,我遇到了麻烦。我看到很多其他 java 图形都可以与 Jpane 一起使用。我不是java专业人士,只是偷偷摸摸。那么有人可以帮我看看我应该使用哪一个吗?

java graphics swing jpanel jframe

0
推荐指数
1
解决办法
1362
查看次数

将if语句转换为for循环?

我在mikroC中编写了一个函数,用于扫描4x4键盘中的按键

void scan_key()
{
    PORTB = 0B11111110;
    if ( PORTB == 0b11101110){
        Row = 1;
        Column = 1;
        return;
    }
    if ( PORTB == 0b11011110){
        Row = 2;
        Column = 1;
        return;
    }
    if ( PORTB == 0b10111110){
        Row = 3;
        Column = 1;
        return;
    }
    if ( PORTB == 0b01111110){
        Row = 4;
        Column = 1;
        return;
    }

    PORTB = 0B11111101;
    if ( PORTB == 0b11101101){
        Row = 1;
        Column = 2;
        return;
    }
    if ( PORTB == 0b11011101){ …
Run Code Online (Sandbox Code Playgroud)

c matrix pic keypad mikroc

-1
推荐指数
1
解决办法
2329
查看次数

这段代码有什么问题公共类Hello {public static void main(){System.out.println("Does not execute");

我在Eclipse中输入了这段代码

 public class Hello 
 {
   public static void main() 
   {
      System.out.println("Doesn't execute");
   }
   // .....
 }
Run Code Online (Sandbox Code Playgroud)

当我按下运行它说它不包含主类型.
我不知道我做错了什么,而且我是java新手.

java eclipse

-1
推荐指数
2
解决办法
371
查看次数