简体   繁体   English

为什么这个java代码没有运行类并打印值? 我尝试了很多但找不到出路

[英]Why is this java code not running the class and printing the values? I have tried a lot but not able to find a way out

class pizza {

public int pizza (int price, int discount) {   

int total = 0; 

total = price - discount; 

return total; 
} 
}
public class MyClass {

public static void main(String[] args) {

int itemNum; 

int price;  

String pizName; 

boolean extraCheese;

itemNum = 1101; 

pizName = "Pepperoni"; 

extraCheese = false; 

System.out.println ("Your order a" +pizName+ "pizza will be served shortly.");

pizza pepperoni = new pizza (50, 10);

System.out.println("Your payment without discount is:" + pepperoni.price); 

}

}

This is my code above any help would be appreciated.这是我上面的代码,任何帮助将不胜感激。 Thank you so much guys.十分感谢大家。 Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. Java 是一种通用计算机编程语言,它是并发的、基于类的、面向对象的,并且专门设计为具有尽可能少的实现依赖性。

The name of the method and class should not be same.方法和类的名称不应相同。 You are trying to initialise instance variable using constructor.您正在尝试使用构造函数初始化实例变量。 But the syntax for the constructor is not correct and also it implicitly returns reference to the object.但是构造函数的语法不正确,并且它隐式地返回对对象的引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法在 Visual Studio Code 上运行 Java! 我尝试了很多 - I can not run Java on Visual Studio Code! I tried a lot 我尝试了java套接字中的连接重置异常,但是我没有发现,这里是代码 - a connection reset exception in java socket ,i have tried but i didn't catch this out,here is code Java,我如何找出哪个类或方法使用大量内存? - Java,How do I find out which class or method USES a lot of memory? 为什么此Java代码不打印Long值? - Why is this Java code not printing Long values? 有没有办法使用 obj.add(i,random.nextInt(MAX_RAND_NUM)) 将值添加到向量中? 然后将值打印出来? - is there a way to have values added to a vector using obj.add(i,random.nextInt(MAX_RAND_NUM)); and then printing the values out? (Java) 为什么我的代码没有打印出完整的数字? - (Java) Why is my code not printing out the full number? java.lang.ArrayIndexOutOfBoundsException:0-我无法弄清为什么代码超出范围 - java.lang.ArrayIndexOutOfBoundsException: 0 - I cant figure out why the code is running out of bounds 为什么在Java中以下代码中Arrayindex越界? 我已经检查了界限,但不明白为什么/ - why is the Arrayindex out of bound in the following code in java? I have checked the bounds but don't understand why/ 如何查找先前未在Spring Batch中运行的任何先前运行的作业/任务? 我尝试了一些代码,但不确定 - How to find any of previously running job/task is not running in spring batch? I hv tried some code but not sure 在Eclipse中运行无法找到该类 - Running in Eclipse is Not Able to Find the Class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM