Yet again my own tutorial. This time its a dice game I made.(Of course text based :x, Improvment will later, java isn't my thing)
So lets begin...
Our choices of operation...Code:import java.util.*; public class mathrandom { protected static Scanner sc = new Scanner(System.in);//The scanner instead of keyboarder public static void main(String[] arg) { System.out.println("Would you like to throw the dice?" +//Input choice "\n1.Yes, please\n2.No thanks"); int dice = sc.nextInt();//Operation
Now the whole code...Code:if(dice == 1) {//if the input was 1 then int nr;//Anything in the range of an integer nr = (int)(Math.random()*6+1);//The random selection of number range 1-6 System.out.println("You got number "+nr);//Printout the dice number } else if(dice == 2){//else if your choice was 2 then System.out.println("What ever ");//Printout this message } else {//else if your choices were not 1 or 2 then it will close it self System.exit(0); } } }
Hope this simple dice game will entertain you guys when you are bored lol.Code:import java.util.*; public class mathrandom { protected static Scanner sc = new Scanner(System.in); public static void main(String[] arg) { System.out.println("Would you like to throw the dice?" + "\n1.Yes, please\n2.No thanks"); int dice = sc.nextInt(); if(dice == 1) { int nr; nr = (int)(Math.random()*6+1); System.out.println("You got number "+nr); } else if(dice == 2){ System.out.println("What ever "); } else { System.exit(0); } } }


LinkBack URL
About LinkBacks


)




Reply With Quote










Bookmarks