linktree - Multiplayer Online Role Playing Game  >  Community  >  General Chat
linktree Topic: Ghost is learning some Java
Pages: [1]   Go Down
Author Topic: Ghost is learning some Java  (Read 1229 times)
0 Members and 1 Guest are viewing this topic. Bookmarked by 0 members.
Offline Ghost

Do not read this or you will go bli
Posts: 162
Gender: Male
« on: April 03, 2011, 05:45:26 am »

Hello guys. What has Ghost been up to lately? Well, I've been deciding on what programming language I should learn. At first I had a go at Python at which I got as far as making a calculator, which was good but still. I like the things Java can do. So, I've learned so far Variables, If statements, User Input, and to make the script output something. All the code I'll post here is made from me. I've got the basics down and so far I have this amazing calculator that just seemed to come to me as I made the class file for it.

Here is the script for those who want to see.
Code: [Select]

// Imports the Scanner which is needed for user
// input.
import java.util.Scanner;

public class JCalc {
 public static void main(String[]args) {
  // What you see at the start of the program.
  System.out.println("Please choose a operation: 1.Add 2.Subtract 3.Divide 4.Multiply");
  Scanner scan = new Scanner(;

  // Prompts user for the operation number.
  System.out.println("Please select your operation: ");
  int op = scan.nextInt();

  // Prompts user for the first number.
  System.out.println("Please enter the first number: ");
  int num1 = scan.nextInt();

  // Prompts user for the second number.
  System.out.println("Please enter the second number: ");
  int num2 = scan.nextInt();

  // Addition
  if (op == 1) {
   int add = num1 + num2;
   System.out.println("The answer: " + add);

  // Subtraction
  if (op == 2) {
   int sub = num1 - num2;
   System.out.println("The answer: " + sub);

  // Division
  if (op == 3) {
   int div = num1 / num2;
   System.out.println("The answer: " + div);


  // Multiplication
  if (op == 4) {
   int mul = num1 * num2;
   System.out.println("The answer: " + mul);


Collector of Chilis and Gems/Pearls/Nuggets of all size and type
Pages: [1]   Go Up
Jump to: