关于netbeans的分配问题 [英] Assignment question on netbeans

查看:67
本文介绍了关于netbeans的分配问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!所以我有这个任务,我必须创建一个墙壁涂料计算器,我在编码时遇到一些困难..



















  import  java.util.Scanner; 

class ProgramA {
public static void main( String [] args)
{
System.out.println( 欢迎使用墙面涂料成本计算器);
int 长度;
int width;
int height;
int cost;

扫描仪键盘= 扫描仪(System.in);

System.out.println( 请输入您的房间长度以米为单位);
length = keyboard.nextInt();

System.out.println( 请输入您的房间宽度以米为单位);
width = keyboard.nextInt();

System.out.println( 请输入您的房间宽度以米为单位);
height = keyboard.nextInt();

System.out.println( 您的总面积为:) ;
cost = length + width * height * 4 ;

System.out.println(cost);

}
}











这个问题的代码是,当我启动程序并输入我的数字时,例如让长度为:5 +宽度:6 *高度:3然后* 4我是总是得到77.



请帮助谢谢!



我尝试了什么:



import java.util.Scanner;



class ProgramA {

public static void main(String [] args)

{

System.out.println(Welcome to Wall Paint Cost Calculator);

int length;

int width;

int height;

int cost;



扫描仪键盘=新扫描仪(System.in);



System.out.println(请以米为单位输入房间长度以下);

length = keyboard.nextInt();



System.out.println(请以米为单位输入房间宽度以下);

width = keyboard.nextInt();



System.out.println(请在房间宽度以米为单位输入);

height = keyboard.nextInt();



System.out.println(你的总面积是:);

cost = length +宽度;



System.out.println(成本);



}

}

解决方案

引用:

这个问题是代码是当我启动程序并输入我的数字时,例如让我们说长度为:5 +宽度:6 *高度:3然后* 4我总是得到77.



不确定是不是问题。当我做5 + 6 * 3 * 4时,我得到77



当你不明白你的代码在做什么或为什么它做它做的时候,答案是调试器

使用调试器查看代码正在执行的操作。它允许你逐行执行第1行并在执行时检查变量,它是一个令人难以置信的学习工具。



调试器 - 维基百科,免费的百科全书 [ ^ ]

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

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [<一个href =https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html\"target =_ blanktitle =New Window> ^ ]



调试器在这里向您展示您的代码是做什么的和你的任务是比较它应该做什么。

调试器中没有魔法,它没有找到错误,它只是帮助你。


高度*宽度* 2为您提供两面墙的区域。



高度*长度* 2给出了另外两面墙的面积



添加两个区域以获得总数。



墙壁当然可以是相同的长度,但这样做允许不同长度的墙壁。



5 * 3 = 15 * 2 = 30

6 * 3 = 18 * 2 = 36


总计66。


Hi ! so i have this assignment where i have to create a Wall paint calculator and I am having some difficulties coding it..









import java.util.Scanner;

class ProgramA{
  public static void main(String [] args)
          {
System.out.println("Welcome To Wall Paint Cost Calculator");
int length;
int width;
int height;
int cost;

Scanner keyboard = new Scanner (System.in);

System.out.println("Please enter below your room length in meters ");
length = keyboard.nextInt ();

System.out.println("Please enter below your room width in meters ");
width = keyboard.nextInt ();

System.out.println("Please enter below your room width in meters ");
height = keyboard.nextInt();

System.out.println("Your total area is:");
cost = length + width * height * 4 ;

System.out.println(cost);

}
}






The problem with this is code is that when i launch the program and type in my numbers for example lets say length is : 5 + width : 6 * height : 3 then * 4 I am always getting 77.

Please help thanks!

What I have tried:

import java.util.Scanner;

class ProgramA{
public static void main(String [] args)
{
System.out.println("Welcome To Wall Paint Cost Calculator");
int length;
int width;
int height;
int cost;

Scanner keyboard = new Scanner (System.in);

System.out.println("Please enter below your room length in meters ");
length = keyboard.nextInt ();

System.out.println("Please enter below your room width in meters ");
width = keyboard.nextInt ();

System.out.println("Please enter below your room width in meters ");
height = keyboard.nextInt();

System.out.println("Your total area is:");
cost = length + width ;

System.out.println(cost);

}
}

解决方案

Quote:

The problem with this is code is that when i launch the program and type in my numbers for example lets say length is : 5 + width : 6 * height : 3 then * 4 I am always getting 77.


Not sure it is a problem. When I do 5+6*3*4, I get 77

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. It allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to.


Height * Width * 2 gives you the area for two walls.

Height * Length * 2 gives the area of the two other walls

Add the two areas to get the total.

Walls of course may be the same length but doing it this way allows for different length walls.

5 * 3 = 15 * 2 = 30
6 * 3 = 18 * 2 = 36

Total 66.


这篇关于关于netbeans的分配问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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