Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 19:39

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



JAVA ENCODING HELP!!

Discussion on JAVA ENCODING HELP!! within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2009
Posts: 12
Received Thanks: 0
JAVA ENCODING HELP!!

Sir can you teach me about this?These program is not a fluent one. and i know that there is a more flexible program to this ..it's a factorial thing

this should be the output:

<<INVALID INPUT SHOULD START FROM 1 to 30>>>

Enter a Number:5
5!=5 x 4 x 3 x 2 x 1 = 120

Press "YES" to repeat: YES
Enter a Number: 10
10!=10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1=3628800

Press "YES" to repeat: YES
Enter a Number: 90
<<INVALID INPUT>>
Enter a Number: 3
3!=3 x 2 x 1=6
Press "YES" to repeat: No

Process Completed...

This is what i've done and maybe it's called a cheating XD i'm using JCREATOR LE 5.00 this is my compiler j2sdk1.4.2_13


Hope you can help me with this ! I will study all your teachings to me. thank you



PHP Code:
import java.io.*;
public class 
Factorial{
public static 
void main(String [] kimthrows IOException{
DataInputStream mik=new DataInputStream(System.in);

int num;
String ans="";

System.out.println("<<Valid input number must be in the range 1 to 30>>>");

do{
System.out.print("Enter a number: ");
num=Integer.parseInt(mik.readLine());

switch (
num){

case 
1:
num=num;
System.out.println("1!= 1 = "+num+"\n");
break;
case 
2:
num=num*1;
System.out.println("2!= 2 x 1 = "+num+"\n");
break;
case 
3:
num=num*2*1;
System.out.println("3!= 3 x 2 x 1 = "+num+"\n");
break;
case 
4:
num=num*3*2*1;
System.out.println("4!= 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
5:
num=num*4*3*2*1;
System.out.println("5!= 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
6:
num=num*5*4*3*2*1;
System.out.println("6!= 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
7:
num=num*6*5*4*3*2*1;
System.out.println("7!= 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
8:
num=num*7*6*5*4*3*2*1;
System.out.println("8!= 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
9:
num=num*8*7*6*5*4*3*2*1;
System.out.println("9!= 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
10:
num=num*9*8*7*6*5*4*3*2*1;
System.out.println("10!= 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
11:
num=num*10*9*8*7*6*5*4*3*2*1;
System.out.println("11!= 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
12:
num=num*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("12!= 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
13:
num=num*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("13!= 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
14:
num=num*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("14!= 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
15:
num=num*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("15!= 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
16:
num=num*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("16!= 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
17:
num=num*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("17!= 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
18:
num=num*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("18!= 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
19:
num=num*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("19!= 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
20:
num=num*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("20!= 20 x 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
21:
num=num*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("21!= 21 x 20 x 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
22:
num=num*21*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("22!= 22 x 21 x 20 x 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
23:
num=num*22*21*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("23!= 23 x 22 x 21 x 20 x 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
24:
num=num*23*22*21*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("24!= 24 x 23 x 22 x 21 x 20 x 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
25:
num=num*24*23*22*21*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("25!= 25 x 24 x 23 x 22 x 21 x 20 x 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
26:
num=num*25*24*23*22*21*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("26!= 26 x 25 x 24 x 23 x 22 x 21 x 20 x 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
27:
num=num*26*25*24*23*22*21*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("27!= 27 x 26 x 25 x 24 x 23 x 22 x 21 x 20 x 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
28:
num=num*27*26*25*24*23*22*21*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("28!= 28 x 27 x 26 x 25 x 24 x 23 x 22 x 21 x 20 x 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
29:
num=num*28*27*26*25*24*23*22*21*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("29!= 29 x 28 x 27 x 26 x 25 x 24 x 23 x 22 x 21 x 20 x 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
case 
30:
num=num*29*28*27*26*25*24*23*22*21*20*19*18*17*16*15*14*13*12*11*10*9*8*7*6*5*4*3*2*1;
System.out.println("30!= 30 x 29 x 28 x 27 x 26 x 25 x 24 x 23 x 22 x 21 x 20 x 19 x 18 x 17 x 16 x 15 x 14 x 13 x 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = "+num+"\n");
break;
default:
System.out.println(" <<Invalid Input>> \n");
break;

}
System.out.print("<<<Enter Yes to repeat or any key to stop>>> ");
ans=mik.readLine();
System.out.println("");
}while (
ans.equalsIgnoreCase("yes"));
}

zepolzirk is offline  
Old 09/28/2011, 10:11   #2

 
Obilee's Avatar
 
elite*gold: 144
Join Date: May 2007
Posts: 62,459
Received Thanks: 29,541
what the...

HTML Code:
  public static void main (String[] args) {
       Scanner scan = new Scanner(System.in);
	System.out.print("n: ");
	int n = scan.nextInt();
	System.out.println("n! = "+fak(n));
   }
   private static long fak(int n){
      if (n==0||n==1) return 1;
      else return n*fak(n-1);
   }
Obilee is offline  
Old 09/28/2011, 10:39   #3
 
elite*gold: 0
Join Date: Jul 2010
Posts: 388
Received Thanks: 196
Quote:
Originally Posted by zepolzirk View Post
Press "YES" to repeat: YES
Where's the "YES" key? Can't find it.
SmackJew is offline  
Old 09/28/2011, 15:25   #4
 
elite*gold: 0
Join Date: Dec 2009
Posts: 12
Received Thanks: 0
Quote:
Originally Posted by SmackJew View Post
Where's the "YES" key? Can't find it.
ahh sorry my mistake it should be

String ans="YES";
zepolzirk is offline  
Old 09/28/2011, 17:35   #5
 
elite*gold: 0
Join Date: Jul 2010
Posts: 388
Received Thanks: 196
Quote:
Originally Posted by zepolzirk View Post
ahh sorry my mistake it should be

String ans="YES";
You don't even realize when you're being made fun of?
SmackJew is offline  
Old 10/02/2011, 21:54   #6
 
elite*gold: 9
Join Date: Dec 2009
Posts: 1,071
Received Thanks: 819
€: Never mind... But I still think you should have a look at loops...
.Infinite is offline  
Reply


Similar Threads Similar Threads
[JAVA Error] Could not create the java virtual machine
07/21/2013 - Technical Support - 10 Replies
Schönen Abend! Leider hat es sich aus einem unerfindlichen Grund ergeben, dass sobald ich die Minecraft.exe starten will die Errormeldung kommt. Die Tips auf Minecraft.net habe ich schon ohne Erfolg befolgt. Hoffe ihr könnt mir weiterhelfen... Mein PC:
[Java] Could not create the Java virtual machine
06/22/2011 - Minecraft - 1 Replies
hallo ihr minecraftler ^^ habe seit heute das problem das wenn ich minecraft starte original als auch cracked das diese fehlermeldung kommt: Java virtual machine Launcher Could not create the Java virtual machine
AFX H.264 Encoding
08/10/2009 - Video Art - 4 Replies
Hallo, Also das Encoden ist bei AFX von den Einstellungen her ja ziemlich eingeschränkt... Gibt es eine Möglichkeit diese Einstellungen zu erweitern? Am besten wär jedoch ein AviSynth Plugin :p, um extern zu encoden. Gibt es sowas? Bedanke mich schonmal im Voraus.
Encoding problem :(
05/19/2008 - General Coding - 1 Replies
I have a problem with encoding when installing PostreSQL, when im choosing a encoding it says "It doesnt belong to my location! :mad: :mad:" Can someone help me finding a encoding for my language, Norwegian! Well, thats about it? Please respond quickly :) Thanks



All times are GMT +1. The time now is 19:39.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.