SilentShriek!!!
Friday, 15 February 2013
BINARY CONVERTER
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
//Convert numbers in base 10 to user specified base or negative base 2
public class Binary
{
public static void main ( String [] args )
{
Scanner input = new Scanner( System.in );
System.out.print("Enter Number in base 10: ");
int base10 = input.nextInt();
System.out.print("Enter Number in required base: ");
int base = input.nextInt();
ArrayList<Integer> result = new ArrayList<Integer>();//Create dynamic array
//Convert from positive base 10 to specified base
if (base10 > 0) {
while ( base10 != 0 ) {
result.add(base10%base);
base10 = base10/base;
}
Collections.reverse(result);//reverse the order of the array
System.out.println( "\nResult in Binary is " + result +"." );
}
//Convert negative base 10 digit to base 2
else {
base10 = (base10 + 1) * -1;
while ((base10 != 0) && (base == 2)) {
if (base10%base == 0) result.add(1);
else if (base10%base == 1)
result.add(0);
base10 = base10/base;
}
Collections.reverse(result);//reverse the order of the array
System.out.println( "\nResult in Binary is " + result +"." );
}
}
}
/*The program works perfectly for unsigned integers
however signed integers seem to be a problem. In
all honesty, i can't be asked to create a proper functioning
logic for signed integers. It's not like most of you view this
blog anyway lol.*/
Sunday, 16 December 2012
A Java Program That Rolls A Pair OF Dice and Sums Up the Outcomes. Now Who Wants To Gamble ;)
import java.util.Scanner;
public class DiceRoll
{
private static final int dice = 6;
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
int x = 0;
int y = 0;
int z = 0;
/*Rolls and sums up outcome of Dice till the loop breaks if 7 is entered at
prompt*/
while ( z != 7 ) {
System.out.println( "Press Any Number To Roll First Die" );
x = input.nextInt();
x = (int) (Math.random() * dice) + 1;
System.out.println( "First Roll = " + x );
System.out.println( "Press Any Number To Roll Second Die" );
y = input.nextInt();
y = (int) (Math.random() * dice) + 1;
System.out.println( "Second Roll = " + y );
System.out.println( "You Rolled a " + (x + y) + "\n" );
System.out.println( "Press 7 To quit Or Any Number To Keep On Rolling" );
z = input.nextInt();
}
}
}
A Little Java Game That Asks A User To Guess A Random Number From The Width Specified By The User.
import java.util.Scanner;
public class GuessNumber
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
System.out.print( "Please Enter A Number To Be Shuffled: " );
int x = input.nextInt();//Asks for width Of Random Number to Be Generated
int y = (int) (Math.random() * x);//Generates Random Number
System.out.print( "Now Guess The Random Number Generated: " );
int z = input.nextInt();//Asks For The User's Number
/*Requests for User number and checks if it
is the newly generated random number*/
while (z != y) {
System.out.println( "\nThis is the right Number " + y );
System.out.print( "Please Try again Till You Get the Right Number: " );
z = input.nextInt();
y = ( int ) ( Math.random() * x );
}
System.out.println( "CORRECT" );//Breaks Loop and Prints if Number Matches
}
}
Tuesday, 20 November 2012
Dynamic Multiplication Table
import java.util.Scanner;
public class MultiplyLoop
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
int counter = 0;
int result = 0;
System.out.print( "Please Enter Time Table To Be Displayed: " );
int table = input.nextInt();
//Creates a Multiplication Table Based On User Input.
while ( counter <= 12 ) {
result = counter * table;
System.out.println( counter + " * " + table + " = " + result );
counter++;
}
}
}
public class MultiplyLoop
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
int counter = 0;
int result = 0;
System.out.print( "Please Enter Time Table To Be Displayed: " );
int table = input.nextInt();
//Creates a Multiplication Table Based On User Input.
while ( counter <= 12 ) {
result = counter * table;
System.out.println( counter + " * " + table + " = " + result );
counter++;
}
}
}
A Java Program That Converts Mbps to MBps.
import java.util.Scanner;
public class Mbps2MBps
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
double mbps, mBps;
System.out.print( "Please Enter Value in Mbps in two decimal places: " );
mbps = input.nextDouble();
//Converts Values from Mega bits/second to Mega bytes/second
mBps = mbps * 0.125;
System.out.println( mbps + "Mbps is " + mBps + "MBps." );
}
}
public class Mbps2MBps
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
double mbps, mBps;
System.out.print( "Please Enter Value in Mbps in two decimal places: " );
mbps = input.nextDouble();
//Converts Values from Mega bits/second to Mega bytes/second
mBps = mbps * 0.125;
System.out.println( mbps + "Mbps is " + mBps + "MBps." );
}
}
Monday, 19 November 2012
A Java Program That Assesses Numbers and Displays Results
import java.util.Scanner;
public class VariousSelections //A Java Program That Will Blow Your Mind (215) lines.
{
public static void main( String[] args)
{
Scanner input = new Scanner( System.in );
int num1, num2, num3, num4, num5, num6, num7, num8,
num9, num10, num11, num12;
System.out.print( "Please Enter a Number For Assessment: " );
num1 = input.nextInt();
numerousSelections( num1 );
System.out.print( "\nPlease Enter First Number: " );
num2 = input.nextInt();
System.out.print( "Please Enter Second Number: " );
num3 = input.nextInt();
twoNumbers( num2, num3 );
System.out.print( "\nPlease Enter Your Age: " );
num4 = input.nextInt();
age( num4 );
System.out.print( "\nPlease Enter First Number: " );
num5 = input.nextInt();
System.out.print( "Please Enter Second Number: " );
num6 = input.nextInt();
largerNumber( num5, num6 );
System.out.print( "\nPlease Enter First Number: " );
num7 = input.nextInt();
System.out.print( "Please Enter Second Number: " );
num8 = input.nextInt();
System.out.print( "Please Enter Third Number: " );
num9 = input.nextInt();
System.out.print( "Please Enter Fourth Number: " );
num10 = input.nextInt();
largerSmallerNumber( num7, num8, num9, num10 );
System.out.print( "\nPlease Enter A Month Number: " );
num11 = input.nextInt();
month( num11 );
System.out.print( "\nPlease Enter A Month Number: " );
num12 = input.nextInt();
monthDays( num12 );
}
public static void numerousSelections( int num1 )
{
if ( num1 == 0 ) {
System.out.println( "Your number is equal to 0" );
}
if ( num1!= 0 ) {
System.out.println( "Your number is not equal to 0" );
}
if ( num1 <= 0 ) {
System.out.println( "Your number is less than or equal to 0" );
}
if (( num1 >= 1 ) && ( num1<= 20 )) {
System.out.println( "Your number is between 1 and 20" );
}
if ((( num1 >= 1 ) && ( num1 <= 20 )) || (( num1 >= 100 ) && ( num1 <= 120 ))) {
System.out.println( "Your number is between 1 and 10 or 100 and 120" );
}
}
public static void twoNumbers( int num2, int num3 )
{
if ( num2 == num3 ){
System.out.println( "The Numbers Are Equal" );
}
else {
System.out.println( "The Numbers Are Not Equal" );
}
}
public static void age( int num4 )
{
if ( num4 < 18 ) {
System.out.println( "User is a teenager who recently hit puberty" );
}
else if (( num4 >= 18 ) && ( num4 <= 21 )) {
System.out.println( "User can Drink Beer" );
}
else {
System.out.println( "User is an Adult" );
}
}
public static void largerNumber( int num5, int num6 )
{
if ( num5 > num6 ) {
System.out.println( num5 + " is the larger of the numbers" );
}
else if ( num5 == num6 ) {
System.out.println( num5 + num6 + " are equal" );
}
else {
System.out.println( num6 + " is the greater of the numbers" );
}
}
public static void largerSmallerNumber( int num7, int num8, int num9, int num10 )
{
if (( num7 > num8) && ( num7 > num9 ) && ( num7 > num10 )) {
System.out.print( num7 + " is larger than the rest while " );
}
if (( num8 > num7) && ( num8 > num9 ) && ( num8 > num10 )) {
System.out.print( num8 + " is larger than the rest while " );
}
if (( num9 > num7) && ( num9 > num8 ) && ( num9 > num10 )) {
System.out.print( num9 + " is larger than the rest while " );
}
if (( num10 > num7) && ( num10 > num8 ) && ( num10 > num9 )) {
System.out.print( num10 + " is larger than the rest while " );
}
if (( num7 < num8) && ( num7 < num9 ) && ( num7 < num10 )) {
System.out.println( + num7 + " is smaller than the rest" );
}
if (( num8 < num7 ) && ( num8 < num9 ) && ( num8 < num10 )) {
System.out.println( + num8 + " is smaller than the rest" );
}
if (( num9 < num7) && ( num9 < num8 ) && ( num9 < num10 )) {
System.out.println( + num9 + " is smaller than the rest" );
}
if (( num10 < num7) && ( num10 < num8 ) && ( num10 < num9 )) {
System.out.println( + num10 + " is smaller than the rest" );
}
}
public static void month( int num11 )
{
if ( num11 == 1) {
System.out.println( "You Are In The Month Of January" );
}
if ( num11 == 2) {
System.out.println( "You Are In The Month Of February" );
}
if ( num11 == 3) {
System.out.println( "You Are In The Month Of March" );
}
if ( num11 == 4) {
System.out.println( "You Are In The Month Of April" );
}
if ( num11 == 5) {
System.out.println( "You Are In The Month Of May" );
}
if ( num11 == 6) {
System.out.println( "You Are In The Month Of June" );
}
if ( num11 == 7) {
System.out.println( "You Are In The Month Of July" );
}
if ( num11 == 8) {
System.out.println( "You Are In The Month Of August" );
}
if ( num11 == 9) {
System.out.println( "You Are In The Month Of September" );
}
if ( num11 == 10) {
System.out.println( "You Are In The Month Of October" );
}
if ( num11 == 11) {
System.out.println( "You Are In The Month Of November" );
}
if ( num11 == 12) {
System.out.println( "You Are In The Month Of December" );
}
}
public static void monthDays( int num12 )
{
if ( num12 == 1) {
System.out.println( "You Are In The Month Of January with 31 days" );
}
if ( num12 == 2) {
System.out.println( "You Are In The Month Of February with 28 or 29 days" );
}
if ( num12 == 3) {
System.out.println( "You Are In The Month Of March with 31 days" );
}
if ( num12 == 4) {
System.out.println( "You Are In The Month Of April with 30 days" );
}
if ( num12 == 5) {
System.out.println( "You Are In The Month Of May with 31 days" );
}
if ( num12 == 6) {
System.out.println( "You Are In The Month Of June with 30 days" );
}
if ( num12 == 7) {
System.out.println( "You Are In The Month Of July with 31 days" );
}
if ( num12 == 8) {
System.out.println( "You Are In The Month Of August with 31 days" );
}
if ( num12 == 9) {
System.out.println( "You Are In The Month Of September with 30 days" );
}
if ( num12 == 10) {
System.out.println( "You Are In The Month Of October with 31 days" );
}
if ( num12 == 11) {
System.out.println( "You Are In The Month Of November with 30 days" );
}
if ( num12 == 12) {
System.out.println( "You Are In The Month Of December with 31 days" );
}
}
}
public class VariousSelections //A Java Program That Will Blow Your Mind (215) lines.
{
public static void main( String[] args)
{
Scanner input = new Scanner( System.in );
int num1, num2, num3, num4, num5, num6, num7, num8,
num9, num10, num11, num12;
System.out.print( "Please Enter a Number For Assessment: " );
num1 = input.nextInt();
numerousSelections( num1 );
System.out.print( "\nPlease Enter First Number: " );
num2 = input.nextInt();
System.out.print( "Please Enter Second Number: " );
num3 = input.nextInt();
twoNumbers( num2, num3 );
System.out.print( "\nPlease Enter Your Age: " );
num4 = input.nextInt();
age( num4 );
System.out.print( "\nPlease Enter First Number: " );
num5 = input.nextInt();
System.out.print( "Please Enter Second Number: " );
num6 = input.nextInt();
largerNumber( num5, num6 );
System.out.print( "\nPlease Enter First Number: " );
num7 = input.nextInt();
System.out.print( "Please Enter Second Number: " );
num8 = input.nextInt();
System.out.print( "Please Enter Third Number: " );
num9 = input.nextInt();
System.out.print( "Please Enter Fourth Number: " );
num10 = input.nextInt();
largerSmallerNumber( num7, num8, num9, num10 );
System.out.print( "\nPlease Enter A Month Number: " );
num11 = input.nextInt();
month( num11 );
System.out.print( "\nPlease Enter A Month Number: " );
num12 = input.nextInt();
monthDays( num12 );
}
public static void numerousSelections( int num1 )
{
if ( num1 == 0 ) {
System.out.println( "Your number is equal to 0" );
}
if ( num1!= 0 ) {
System.out.println( "Your number is not equal to 0" );
}
if ( num1 <= 0 ) {
System.out.println( "Your number is less than or equal to 0" );
}
if (( num1 >= 1 ) && ( num1<= 20 )) {
System.out.println( "Your number is between 1 and 20" );
}
if ((( num1 >= 1 ) && ( num1 <= 20 )) || (( num1 >= 100 ) && ( num1 <= 120 ))) {
System.out.println( "Your number is between 1 and 10 or 100 and 120" );
}
}
public static void twoNumbers( int num2, int num3 )
{
if ( num2 == num3 ){
System.out.println( "The Numbers Are Equal" );
}
else {
System.out.println( "The Numbers Are Not Equal" );
}
}
public static void age( int num4 )
{
if ( num4 < 18 ) {
System.out.println( "User is a teenager who recently hit puberty" );
}
else if (( num4 >= 18 ) && ( num4 <= 21 )) {
System.out.println( "User can Drink Beer" );
}
else {
System.out.println( "User is an Adult" );
}
}
public static void largerNumber( int num5, int num6 )
{
if ( num5 > num6 ) {
System.out.println( num5 + " is the larger of the numbers" );
}
else if ( num5 == num6 ) {
System.out.println( num5 + num6 + " are equal" );
}
else {
System.out.println( num6 + " is the greater of the numbers" );
}
}
public static void largerSmallerNumber( int num7, int num8, int num9, int num10 )
{
if (( num7 > num8) && ( num7 > num9 ) && ( num7 > num10 )) {
System.out.print( num7 + " is larger than the rest while " );
}
if (( num8 > num7) && ( num8 > num9 ) && ( num8 > num10 )) {
System.out.print( num8 + " is larger than the rest while " );
}
if (( num9 > num7) && ( num9 > num8 ) && ( num9 > num10 )) {
System.out.print( num9 + " is larger than the rest while " );
}
if (( num10 > num7) && ( num10 > num8 ) && ( num10 > num9 )) {
System.out.print( num10 + " is larger than the rest while " );
}
if (( num7 < num8) && ( num7 < num9 ) && ( num7 < num10 )) {
System.out.println( + num7 + " is smaller than the rest" );
}
if (( num8 < num7 ) && ( num8 < num9 ) && ( num8 < num10 )) {
System.out.println( + num8 + " is smaller than the rest" );
}
if (( num9 < num7) && ( num9 < num8 ) && ( num9 < num10 )) {
System.out.println( + num9 + " is smaller than the rest" );
}
if (( num10 < num7) && ( num10 < num8 ) && ( num10 < num9 )) {
System.out.println( + num10 + " is smaller than the rest" );
}
}
public static void month( int num11 )
{
if ( num11 == 1) {
System.out.println( "You Are In The Month Of January" );
}
if ( num11 == 2) {
System.out.println( "You Are In The Month Of February" );
}
if ( num11 == 3) {
System.out.println( "You Are In The Month Of March" );
}
if ( num11 == 4) {
System.out.println( "You Are In The Month Of April" );
}
if ( num11 == 5) {
System.out.println( "You Are In The Month Of May" );
}
if ( num11 == 6) {
System.out.println( "You Are In The Month Of June" );
}
if ( num11 == 7) {
System.out.println( "You Are In The Month Of July" );
}
if ( num11 == 8) {
System.out.println( "You Are In The Month Of August" );
}
if ( num11 == 9) {
System.out.println( "You Are In The Month Of September" );
}
if ( num11 == 10) {
System.out.println( "You Are In The Month Of October" );
}
if ( num11 == 11) {
System.out.println( "You Are In The Month Of November" );
}
if ( num11 == 12) {
System.out.println( "You Are In The Month Of December" );
}
}
public static void monthDays( int num12 )
{
if ( num12 == 1) {
System.out.println( "You Are In The Month Of January with 31 days" );
}
if ( num12 == 2) {
System.out.println( "You Are In The Month Of February with 28 or 29 days" );
}
if ( num12 == 3) {
System.out.println( "You Are In The Month Of March with 31 days" );
}
if ( num12 == 4) {
System.out.println( "You Are In The Month Of April with 30 days" );
}
if ( num12 == 5) {
System.out.println( "You Are In The Month Of May with 31 days" );
}
if ( num12 == 6) {
System.out.println( "You Are In The Month Of June with 30 days" );
}
if ( num12 == 7) {
System.out.println( "You Are In The Month Of July with 31 days" );
}
if ( num12 == 8) {
System.out.println( "You Are In The Month Of August with 31 days" );
}
if ( num12 == 9) {
System.out.println( "You Are In The Month Of September with 30 days" );
}
if ( num12 == 10) {
System.out.println( "You Are In The Month Of October with 31 days" );
}
if ( num12 == 11) {
System.out.println( "You Are In The Month Of November with 30 days" );
}
if ( num12 == 12) {
System.out.println( "You Are In The Month Of December with 31 days" );
}
}
}
Sunday, 18 November 2012
Linear Programming
A video footage simplifying Linear Programming and its implementation in a real life scenario.
Hope you enjoy it, i find it exhilarating :)
Subscribe to:
Posts (Atom)