Java项目库转换器net beans有帮助 [英] Java project base converter net beans help

查看:71
本文介绍了Java项目库转换器net beans有帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个编程任务(在java中,我使用net beans dos来编写这个)。此分配需要显示代码中列出的二进制转换。问题是,输出以错误的顺序向后/以错误的顺序显示Base 2,Base 5,Base 7和Base 8转换,并给出一个奇怪的长对话消息(请在NETBEANS中首先测试这个,因此您可以看到问题)。那么有人可以看看我现在拥有的东西,并将其修复到输出中正确显示赋值的位置。谢谢。请同时显示输出。





I have a programming assignment (in java, I use net beans dos to write this). This assignment needs to show the binary conversion as listed within the code. The issue is, the output displays the Base 2, Base 5, Base 7, and Base 8 conversions backwards/ in the wrong order and gives a weird long dialog message (PLEASE TEST THIS IN NETBEANS FIRST SO YOU CAN SEE THE ISSUE). So could someone take a look at what I have now, and fix it to where it displays the assignment correctly in the output. Thanks. Please also show the output.


package base.project;
import javax.swing.*;
public class BaseProject {
	public static String output = "";
	private static void convertobase(int n, int i){
		output += "\n the number " + n + " converted to base " + i;
		while (n > 0){
			output += " " + n%i;
			n = n / i;

		}

		output += "\n is " + output;
		JOptionPane.showMessageDialog(null, output);


	}
	public static void main(String[] args) {
		while (true){
			String input = JOptionPane.showInputDialog("enter any integer number \n");
			int n = Integer.parseInt(input);
			String in = JOptionPane.showInputDialog("\n Make the folowing selection"
			+ "\n to convert to decimal number"
			+ "\n2 to conver to base 2"
			+"\n5 to convert to base 5"
			+ "n7 to conver to base 7"
			+ "\n8 to convert to base 8");
			int selection = Integer.parseInt(in);
			switch(selection){
				case 2:
				convertobase(n, 2);
				break;
				case 5:
				convertobase(n, 5);
				break;
				case 7:
				convertobase(n, 7);
				break;
				case 8:
				convertobase(n, 8);
				break;
			}

		}
	}
}





我尝试了什么:



我已经完成了作业,但它无法正常工作。



What I have tried:

I have completed the assignment however it's not working properly.

推荐答案

我认为现在是时候停止猜测你的代码在做什么了。是时候看到你的代码正在执行并确保它能达到预期的效果。



调试器是你的朋友。它会告诉你你的代码到底在做什么。

一步一步地执行,检查变量,你会发现它有一个停止做你期望的点。

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

http://docs.oracle .com / javase / 7 / docs / technotes / tools / windows / jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]



在yu建立答案的地方特别注意。

如果答案是相反的顺序,你可以按相反的顺序构建它!
I think it is time for you to stop guessing what your code is doing. It is time to see your code executing and ensuring that it does what you expect.

The debugger is your friend. It will show you what your code is really doing.
Follow the execution step by step, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

Pay special attention at the place where yu build the answer.
If the answer is in reverse order, you build it in reverse order !


这篇关于Java项目库转换器net beans有帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆