hi,my name is dayo.i am new to java programming i am bout to write my first program which i copied from a textbook i am reading.
// A program to display the message
// "Hello World!" on standard output
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
} // end of class HelloWorld
but the compiler is giving an error system.out.print class.the compiler made a suggestion 1 should be a package class before it can be used by the compiler.pls i do i go about it.thank you.
Provide two alternatives (1 for loop and 1 while loop) to the loop in fig. 5.12 that does not change the programs output but also does not use a "break" statement. Modify the sample code below to have a single return statement. Prepare all three modifications in a Word document with a discussion as to why using break in this way as well as using multiple return statements is not considered good programming form by most in the field.
Sample Code:
public boolean isTheFirstOneBigger(int num1, int num2)
{
if (num1 > num2)
{
return true;
}
Hi,
I'm new to java programming and i need the explanation why we use
public static void main(String args[])
and why we use "main" only rather than other word...please help me....
public static void main(String[] args)
{
Scanner console = new Scanner(System.in);
System.out.print("Enter the value of a: ");
int a = console.nextInt();
System.out.print("Enter the value of b: ");
int b = console.nextInt();
System.out.print("Enter the value of h: ");
int h = console.nextInt();
double area = (a + b) * h / 2;
System.out.println("Area = " + "(" + a + " + " + b + ")" + " * " + h + " / " + 2 );
System.out.println("Area = " + area);
if ( a > 0 || b > 0 || h > 0)
break;
int count = 0;
for (; n = area; n++)
{
count++;
}
System.out.println("The number of trapezium calculated: " + count);
System.out.println("End.");
}
How do I use scanner for this code and calculate & print the area of the trapezium as many time until the user key in a non-positive input.
public class NetbeanTest{
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.print("Enter Operator (+,-,*,/): ");
String plan = console.nextLine();
System.out.print("Enter Value 1: ");
int num1 = console.nextInt();
System.out.print("Enter Value 2: ");
int num2 = console.nextInt();
int result;
if (plan.equals(" + ")) result = num1 + num2; {
System.out.println("Result of " + num1 + " + " + num2 + " = " + result);}
if (plan.equals(" - ")) result = num1 - num2; {
System.out.println("Result of " + num1 + " - " + num2 + " = " + result);}
if (plan.equals(" * ")) result = num1 * num2; {
System.out.println("Result of " + num1 + " * " + num2 + " = " + result); }
if (plan.equals(" / ")) result = num1 / num2; {
System.out.println("Result of " + num1 + " / " + num2 + " = " + result);}
}}
// What went wrong?//