Question

answer for how it would be evaluated in Java without writing a code for it. a)...

answer for how it would be evaluated in Java without writing a code for it.

a) 17 + 2 - 5 / 5

b) 2 + 3 * 5 - 2

c) 3 * 2 / 3 + 8

d) 6 % 2 * 10

Problem 2

: Write an application in java that inputs one number consisting of 5 digits (e.g.

12345) from the user, separates the number into its individual digits and prints the digits

separated from one another by three spaces each (e.g. 1    2    3    4    5).

Assume that the user enters the correct number of digits. What happens when

you enter a number with more than five digits? What happens when you enter a number

with fewer than five digits?

Problem 3:

Write an application in java that reads an integer and determines and prints

whether it’s odd or even.

Problem 4

: Write an application that calculates the squares and cubes of the numbers

from 0 to 10 and prints it in tabular format

Problem 5

: Write a in java program that inputs five integers and determines and prints the

number of negative integers entered, number of positive integers entered and the

number of zeros entered.

Homework Answers

Answer #1

problem 1 .

In java every operator has its priority that is called operator precedence .

so in java operator precedence is :-

1 .) * / %    (multiplication , division and modulus operator have same priority so the which will encounter first from left in an expression will be evaluated first ).

2.) + - (Addition and multiplication have same priority so the which will encounter first from left in an expression will be evaluated first ).

there are many more operator in java and every operator have its priority .

below is the attached table with operators with its priority

Level Operator Description Associativity
16 []
.
()
access array element
access object member
parentheses
left to right
15 ++
--
unary post-increment
unary post-decrement
not associative
14 ++
--
+
-
!
~
unary pre-increment
unary pre-decrement
unary plus
unary minus
unary logical NOT
unary bitwise NOT
right to left
13 ()
new
cast
object creation
right to left
12 * / % multiplicative left to right
11 + -
+
additive
string concatenation
left to right
10 << >>
>>>
shift left to right
9 < <=
> >=
instanceof
relational not associative
8 ==
!=
equality left to right
7 & bitwise AND left to right
6 ^ bitwise XOR left to right
5 | bitwise OR left to right
4 && logical AND left to right
3 || logical OR left to right
2 ?: ternary right to left
1 =   +=   -=
*=   /=   %=
&=   ^=   |=
<<= >>= >>>=
assignment right to left

Coming to equations

a) 17 + 2 - 5 / 5

first division operator will be evaluated then addition and them subtraction

so after evaluation answer will come i.e. = 18

b) 2 + 3 * 5 - 2

first multiplication then addition and then subtraction will be evaluated

so after evaluation answer will come i.e. = 15

c) 3 * 2 / 3 + 8

first multiplication operator will be evaluated then division and then addition

so after evaluation answer will be = 10

d) 6 % 2 * 10

first modulus then multiplication operator will be evaluated

so after evaluation answer will be = 0

PROBLEM 2.

program: -

import java.util.Scanner;
public class splitdigit {
   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       int num=sc.nextInt();
       String s="";
       while (num > 0) {
            s="   "+(num%10)+s;
            num = num / 10;
       }
       System.out.println(s.trim());
   }
}

output : -

PROBLEM 3.

Program : -

import java.util.Scanner;
public class evenorodd {
   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       int num=sc.nextInt();
       if(num%2==0) {
           System.out.println("even");
       }else {
           System.out.println("odd");
       }
   }
}

output :-

PROBLEM 4.

program : -

public class SQUAREANDCUBE {
   public static void main(String[] args) {
       System.out.println("SQUARE\tCUBE");
       for(int i=0;i<=10;i++) {
           System.out.println(i*i+"\t"+i*i*i);
       }
   }
}

output : -

PROBLEM 5.

Program : -

import java.util.Scanner;
public class SQUAREANDCUBE {
   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       int n=0,p=0,z=0;
       int num;
       for(int i=0;i<5;i++) {
           num=sc.nextInt();
           if(num<0)n++;
           if(num>0)p++;
           if(num==0)z++;
       }
       System.out.println("Negative = "+n+"\nPositive = "+p+"\nZero = "+z);
      
   }
}

output : -

Know the answer?
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
Similar Questions
Write a Java program that gets a 4x4 array of numbers and that calculates the sum...
Write a Java program that gets a 4x4 array of numbers and that calculates the sum and average of numbers on the main diagonal, ie the diagonal that goes from the left corner down to the right corner. Examples of resulting programs are: Enter a 4x4 matrix row by row: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 The sum of numbers in the diagonal is: 16 The average of numbers in...
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
Write a java program "without using Strings using loops and methods "that lets the user to...
Write a java program "without using Strings using loops and methods "that lets the user to enter any two integers and weave them digit by digit and print the result of weaving their digits together to form a single number. Two numbers x and y are weaved together as follows. The last pair of digits in the result should be the last digit of x followed by the last digit of y. The second-to-the-last pair of digits in the result...
[10 marks] (SumDigits.java) Write code that asks the user to enter an integer between 100 and...
[10 marks] (SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The program finds and displays the three digits in the number. The program also calculates and displays the sum of the three digits. A sample run is shown below: Enter a number between 100 and 999: 528 The three digits in the number are: 5 2 8 The sum of the three digits is: 15
Write a complete Java program to solve the following problem. Read two positive integers from the...
Write a complete Java program to solve the following problem. Read two positive integers from the user and print all the multiple of five in between them. You can assume the second number is bigger than the first. For example if the first number is 1 and the second number is 10, then your program should output 5 10 Note: There is a white space in between the numbers. Java programming please answer ASAP before 2:30
JAVA 4.35 (Sides of a Triangle) Write an application that reads three nonzero values entered by...
JAVA 4.35 (Sides of a Triangle) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Here's the code: import java.util.Scanner; class TriangleYN {    public static void main(String[] args) {        Scanner input = new Scanner(System.in);               double a;        double b;        double c;               System.out.print("Enter three sizes, separated by spaces(decimals values are acceptable):");...
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
(SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The...
(SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The program finds and displays the three digits in the number. The program also calculates and displays the sum of the three digits. A sample run is shown below: Enter a number between 100 and 999: 528 The three digits in the number are: 5 2 8 The sum of the three digits is: 15 Note: You must use integer division and modulo division to...
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the...
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the user to input a number, N * Then use a for loop to calculate and display the first N fibonocci numbers * For example, if the user enters 5, the output should be: * 1, 1, 2, 3, 5 * * if the user enters 10, the output should be: * 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
java 8.1: Frequency Design and implement an application that reads an arbitrary number of integers that...
java 8.1: Frequency Design and implement an application that reads an arbitrary number of integers that are in the range 0 to 50 inclusive and counts how many occurrences of each are entered. After all input has been processed, print all of the values (with the number of occurrences) that were entered one or more times. The output should be one frequency count per line with the following format: 3 occurrences of 2 7 occurrences of 5 SPECIFICATION OF NAMES:...