Top

Number check


Java Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  1.4 (of 5 scores)
Date Added  Nov 20, 2008
Last Updated  Nov 20, 2008
Tags  bigger  biggest  check  digit  integer  java  number  range  script  smaller  smallest  than 

Introduction



My first Java code!

I was getting a bit sick of mIRC seeing as it didn't have any practical uses in life. Although, this really doesn't serve any practical purpose either but I reckon it's a great start for only starting an hour ago. :P

I mainly posted it up here so that people can get an insight into Java. I have also added tons of comments so a user can *hopefully* follow the code and understand what it is doing. It's very basic, and something that might seem pointless, but it could be good for people just starting Java, ya never know.

The script will check by the two variables (you can change the values) and return information depending on which is bigger.

---How to use---
You'll need to open your Java compiler and paste the code in.

I CANNOT STRESS IT ENOUGH THAT YOU MUST KNOW WHAT YOU ARE DOING LOADING THIS. The filename MUST be Numbercheck.java. Otherwise, if it isn't, it will not work. And yes, it IS CASE SENSITIVE.

If you do not have a compiler and want to try this, I suggest getting JCreator. It's totally free and easy to use. http://www.jcreator.com/download.htm

If anyone knows how to do the $? equivalent in Java, please let me know! I want to make the user able to input the variable values.

Grab the Code

/**
 * @(#)Numbercheck.java
 *
 *
 * @author Neptune
 * @version 1.00 2008/11/20
 */
 
 
public class Numbercheck {
 
	//Defining the class (must be exactly the same as the filename (case-sensitive, too)
 
	public static void main(String[] args) {
 
		//Declares it accessible from outside the class
 
		int a = 10, b = 5;
 
		//Sets the variables
		//a is declared as 10
		//b is declared as 5
		//You can change the variable values to whatever you want to test the script better
 
			System.out.println("First number:"+a);
			System.out.println("Second number:"+b);
 
			//These two lines print out the first and second number
			//The + sign is used to combine strings
 
		if (a > b) {
 
			//Check if a is bigger than b
 
			System.out.println("Biggest number:"+a);
 
			//Print out that a is bigger than b
 
		}
	    else {
 
	    	//This basically means if the first statement is false, do whatever else I put under the else
	    	//In this case, it would mean that b is bigger than a
 
			System.out.println("Biggest number:"+b);
 
			//Print out that b is bigger than a
 
	    }
	    System.out.println("Range:"+(a-b));
 
	    //Print out the difference between the biggest and smallest number
	    //You can simply enclose an equation in () brackets to make it calculate itself
	    //This line will be printed out no matter what, as it is outside the if and else brackets
 
	}
}

Comments

  (7)  RSS
^Neptune
Comments: 598
 
Java Snippet:  Number check
Posted on Nov 20, 2008 3:40 pm
Screenshot has been added.

Considering I have only been learning for an hour, I think I'm doing pretty well. =]
mountaindew
Comments: 1,826
 
Java Snippet:  Number check
Posted on Nov 20, 2008 3:48 pm
You should have the user enter two numbers
^Neptune
Comments: 598
 
Java Snippet:  Number check
Posted on Nov 20, 2008 3:56 pm
That's what I said in the intro, lol

Still trying to figure out how you can do it.
Firstmate
Comments: 119
 
Java Snippet:  Number check
Posted on Nov 20, 2008 6:56 pm
Edit: bad link
^Neptune
Comments: 598
 
Java Snippet:  Number check
Posted on Nov 21, 2008 1:52 am
What's with the 1.4?

I know it's not that amazing and all but it's not either ripped or incomplete. =/
mountaindew
Comments: 1,826
 
Java Snippet:  Number check
Posted on Apr 4, 2009 8:23 pm
I think this would be it:
Code:

import java.util.Scanner;

class keyboardinput {
   
   /**
    * Method main
    *
    *
    * @param args
    *
    */
   public static void main(String[] args) {
      Scanner myScanner = new Scanner(System.in);
      int a,b;
      a = myScanner.nextInt();
      b = myScanner.nextInt();
   }
}
Joshuaxiong1
Comments: 127
 
Java Snippet:  Number check
Posted on Nov 16, 2009 1:31 pm
I wish I can play like this like other Java in here.

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom