Git Product home page Git Product logo

i-mmantech's People

Contributors

i-mmantech avatar

Stargazers

 avatar

Watchers

 avatar

i-mmantech's Issues

Creating a Simple calculator using the if else if and else statements in JAVA

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanMe = new Scanner(System.in);

System.out.println(" This is a Calculator Sensor \n");



System.out.print("Enter the first Number: ");

double number1 = scanMe.nextDouble();



System.out.print("Enter the second Number: ");

double number2 = scanMe.nextDouble();

scanMe.nextLine();





System.out.println("What operation do you want to perform? ");

String operation = scanMe.nextLine();


// sum for addition
if (operation.equals("sum")) {

  System.out.printf("%f + %f = %f", number1,number2, number1 + number2);

// sub for subtraction
} else if (operation.equals("sub")) {

  System.out.printf("%f - %f = %f", number1,number2, number1 - number2);

// mul for multiplication 
} else if (operation.equals("mul")) {

  System.out.printf("%f * %f = %f", number1,number2, number1 * number2);

 
// div for division 
} else if (operation.equals("div")) {

  if (number2 == 0) {

    System.out.println("can not divide by ZERO(0).");

  } else {

    System.out.printf("%f / %f = %f", number1,number2, number1 / number2);

  }

} else{

  System.out.printf("%s is not a supported operation! ", operation);

}



scanMe.close();


}

}

2D arrays in JAVA

Multidimensional arrays
public class Main {
public static void main(String[] args) {
// 2D array = an array of arrays

	String[][] cars = new String[3][3];

	

	cars[0][0] = "Camaro";

	cars[0][1] = "Corvette";

	cars[0][2] = "Silverado";

	cars[1][0] = "Mustang";

	cars[1][1] = "G-Wagon";

	cars[1][2] = "Ferrari";

	cars[2][0] = "Lambo";

	cars[2][1] = "Ranger";

	cars[2][2] = "Tesla";

	

	for(int i=0; i<cars.length; i++) {

		System.out.println();

		for(int j=0; j<cars[i].length; j++) {

		System.out.print(cars[i][j] +" ");

                    }

	}


}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.