Showing posts with label Multiple operations and precedence. Show all posts
Showing posts with label Multiple operations and precedence. Show all posts

Wednesday, October 30, 2013

1.05 - Multiple operations and precedence

/*
 * Autor: Juan Antonio Ripoll
 * Date: 30/10/13
 * 
 * Write a JAVA program to print the result of multiplying two numbers which 
 * will entered by the user.
 * */

import java.util.Scanner;

public class Main {

 public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  
  System.out.print("Enter 1st number: ");
  int number1 = in.nextInt();
  
  System.out.print("Enter 2st number: ");
  int number2 = in.nextInt();
  
  System.out.println(number1 + " x " + number2 + " = " + number1 * number2);
 }

}

1.04 - Multiple operations and precedence

/*
 * Autor: Juan Antonio Ripoll
 * Date: 30/10/13
 * 
 * Create a JAVA program to print the result of the following operations: 

   • -1 + 3 * 5 
   • (24+5) % 7 
   • 15 + -4*6 / 11 
   • 2 + 10 / 6 * 1 - 7 % 2   
 * */

public class Main {

 public static void main(String[] args) {
  System.out.println(-1+3*5);
  System.out.println((24+5) % 7);
  System.out.println(15+-4*6/11);
  System.out.println(2+10/6*1-7%2);
 }

}