Question

int a = 5, b = 4, c = -10;       if(!(a>b++))             System.out.println("Value of a...

int a = 5, b = 4, c = -10;

      if(!(a>b++))

            System.out.println("Value of a is: " + a);

System.out.println("We are inside the if-statement!");

            System.out.println("Value of b is: " + b);

      }else if (c%2 != 0 & c < 0){ //logical error (curly brace), syntax error

            c = c / 0;

            System.out.println(“We are now in the else section and c is a negative odd number!” + c);
      }

      else

            System.out.println(“c is even?”);

      System.out.println("We are now back outside the if-statement!");

Is there any mistakes for this programming?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
//Main.java
public class Main {
  public static void main(String [] args) {
    int a = 5, b = 4, c = -10;
    //If it has a single statement then we can write the statement without using curly brace
    //Otherwise we have to use curly brace and write those statements inside the curly braces
    if(!(a>b++)) {
      System.out.println("Value of a is: " + a);
      System.out.println("We are inside the if-statement!");
      System.out.println("Value of b is: " + b);
    }
    else if (c%2 != 0 & c < 0){ //logical error (curly brace), syntax error
      c = c / 0;
      System.out.println("We are now in the else section and c is a negative odd number!" + c);
    }
    //As it is having single statement we can write this statement without using curly brace
    else
        System.out.println("c is even?");
    System.out.println("We are now back outside the if-statement!");
  }
}

Please upvote the solution if it helped. Thanks!

Note: Please comment below if you have any doubts

Add a comment
Know the answer?
Add Answer to:
int a = 5, b = 4, c = -10;       if(!(a>b++))             System.out.println("Value of a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What is the value of GPA when grade is 'B' in the following code segment? int...

    What is the value of GPA when grade is 'B' in the following code segment? int GPA=0; switch (grade) { case 'A': case 'a': GPA = GPA + 1; case 'B': case 'b': GPA = GPA + 1; case 'C': case 'c': GPA = GPA + 1; case 'D': case 'd': GPA = GPA + 1; } 4 3 2 1 None of the above #2.   Branching - switch statements... Extra info/hint? It's free What is the value of GPA when...

  • public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc...

    public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc = new Scanner(System.in);         String choice = "y";         while (choice.equalsIgnoreCase("y")) {             // get the input from the user             System.out.println("DATA ENTRY");             double monthlyInvestment = getDoubleWithinRange(sc,                     "Enter monthly investment: ", 0, 1000);             double interestRate = getDoubleWithinRange(sc,                     "Enter yearly interest rate: ", 0, 30);             int years = getIntWithinRange(sc,                     "Enter number of years: ", 0, 100);             System.out.println();            ...

  • a) int a -5, b 6, c 7 System.out.printin(a--b-- System.out.printin(a---a- System.out.println (a+++b+++c) Output from part a)...

    a) int a -5, b 6, c 7 System.out.printin(a--b-- System.out.printin(a---a- System.out.println (a+++b+++c) Output from part a) int vl-10, v2 -20 if (viV2 30 11 v2+21) Output from part b) System.out.printin("1."+vi+""2) System.out.println("2. " +vl+"+ v2) System.out.printin("3."+vl+"v2)L else if (v2-20 && ++v1 11)( elset Output from part c) int x - 10, y - 20 System.out.println (x) System.out.println(y)

  • Something is wrong with each of the following pieces of code. Use A or B to...

    Something is wrong with each of the following pieces of code. Use A or B to label whether the error is from: A. Compiler ErrorB. Logical or Runtime Error Use minor edits to correct the code. int x System.out.println("value of x is:x) if (x820) System.out.println("Your number was even!") System.out.println("Your number is odd!") else double avg numl+num2+num3/3.0 if (x > y) f double max-x; else max-y: 5. double answer Math.sqrt (/25;

  • 31. The following code segment is syntactically correct:              int number{20};          cout << number <<...

    31. The following code segment is syntactically correct:              int number{20};          cout << number << setbase(16) << " " << number                               << setbase(10) << " " << number                                 << showpos << " " << number << endl;                 T__   F__       32. The following statement wants to determine if ‘count’ is outside the     range of 0 through 100:             if (count < 0 && count > 100)                                             T__   F__ 33. There is...

  • (use only variables, expression, conditional statement and loop of c programming) ***C programming** int sum_of_cubes(int n)...

    (use only variables, expression, conditional statement and loop of c programming) ***C programming** int sum_of_cubes(int n) { } int quadrant(int x, int y) { } int num_occurrences_of_digit(long num, int digit) { return 0; } 3.1 int sum_of_cubes(int n) This function should return the sum of the cubes of the first n integers. For example, if n is 4, it should return 13 +23+ 39 +4°. There is a simple formula for the result: 3x = ((n + 1)) = +...

  • int a=3, b =4, c[10]; int *p; c[10] is initialized as all elements having a value...

    int a=3, b =4, c[10]; int *p; c[10] is initialized as all elements having a value of 2. Write C statements for the following: Make p point to the location of a. Assign b to have its current value plus the value pointed to by p. Assign the value of what p is pointing to equal to 0. Make p point to the third element of c array i.e., first element is c[0] Now assign to b the contents of...

  • 1) int value = 24; int divisor = 5; value % divisor is a) 4 b)...

    1) int value = 24; int divisor = 5; value % divisor is a) 4 b) 1 c) 3 d) 0 e) 2 2) int value = 45; int divisor = 4; What is the result of value / divisor? a) 12 b) 11.25 c) 11 d) 10 3) Assume: int x[][] = {{ 1, 2 }, { 3, 4, 5 }, { 4, 5, 4, 9 }}; What are the values of? x.length? x[ 0 ].length? x[ 1 ].length?...

  • With a Scanner object created as follows, what method do you use to read an int...

    With a Scanner object created as follows, what method do you use to read an int value? Scanner input = new Scanner(System.in); A. input.int(); B. input.nextInt(); C. input.integer(); D. input.nextInteger(); What is the output of the following code? x = 0; if (x > 0) System.out.println("x is greater than 0"); else if (x < 0) System.out.println("x is less than 0"); else System.out.println("x equals 0"); A. x is greater than 0 B. x is less than 0 C. x equals 0...

  • python programming X Canvas 4 → XCO Question 26 10 pts (SHORT ANSWER) Define a function...

    python programming X Canvas 4 → XCO Question 26 10 pts (SHORT ANSWER) Define a function named find_even_odd that has 1 parameter: num. When the function is called, it should use an if/else statement to determine whether the variable num is an even or odd number and display appropriate message as follows: • If the value in num is an even number, the progr will output the message: "XX is an EVEN number", where XX is the value in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT