d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help Algorithm-program Code > Must Be Working At Jcreator
12Next
Add Reply New Topic New Poll
Member
Posts: 2,869
Joined: Aug 6 2012
Gold: 4.00
Jun 25 2013 05:51am
I need this to be done to algorithm>>>Program Code Must be working at JCreator

This is Easy Problem/Basic

Problem:

Let a user input two numbers.
Determine the higher valuve then display all the whole numbers from the lower value to the higher value

120fg for this activity.
Member
Posts: 2,478
Joined: Jan 4 2007
Gold: 7,545.00
Jun 25 2013 06:33am
Did you really need to post this twice?
Member
Posts: 2,869
Joined: Aug 6 2012
Gold: 4.00
Jun 25 2013 06:46am
Quote (DirtyRasa @ Jun 25 2013 08:33pm)
Did you really need to post this twice?


nope,i posted in a different sub fourm(web language)
Member
Posts: 6,864
Joined: Dec 5 2007
Gold: 0.90
Jun 25 2013 07:23am
like that?
Code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class main {

private static int i;
private static int j;

/**
 * @param args
 */
public static void main(String[] args) {

 System.out.println("Enter two Numbers seperated with ','\n");
 
 try{
     BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
     String input = bufferRead.readLine();
 
     String[] numbers = input.split(",");
     
     i = Integer.parseInt(numbers[0]);
     j = Integer.parseInt(numbers[1]);
     
 }
 catch(IOException e)
 {
  e.printStackTrace();
 }
 
 if(i>j){
  while(j<=i){
   System.out.println(j);
   j++;
  }
 }else{
  while(i<j){
   System.out.println(i);
   i++;
  }
 }
}
}

will explode if you dont enter numbers like 21,2
also if you want to read more then one like you need a loop

This post was edited by golddigga on Jun 25 2013 07:31am
Member
Posts: 2,869
Joined: Aug 6 2012
Gold: 4.00
Jun 25 2013 07:48am
Quote (golddigga @ Jun 25 2013 09:23pm)
like that?
Code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class main {

private static int i;
private static int j;

/**
 * @param args
 */
public static void main(String[] args) {

 System.out.println("Enter two Numbers seperated with ','\n");
 
 try{
     BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
     String input = bufferRead.readLine();
 
     String[] numbers = input.split(",");
     
     i = Integer.parseInt(numbers[0]);
     j = Integer.parseInt(numbers[1]);
     
 }
 catch(IOException e)
 {
  e.printStackTrace();
 }
 
 if(i>j){
  while(j<=i){
   System.out.println(j);
   j++;
  }
 }else{
  while(i<j){
   System.out.println(i);
   i++;
  }
 }
}
}

will explode if you dont enter numbers like 21,2
also if you want to read more then one like you need a loop


i need algorithm and program code

This post was edited by Yappie on Jun 25 2013 07:49am
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Jun 25 2013 08:02am
Code
System.out.println( "Enter number 1: " );
   int num1 = new Scanner( System.in ).nextInt( );
   System.out.println( "Enter number 2: " );
   int num2 = new Scanner( System.in ).nextInt( );
   int higherNumber;
   System.out.println( "Highest number: "
       + (higherNumber = (num1 > num2) ? num1 : num2) );
   int lowerNumber = (num1 == higherNumber) ? num2 : num1;
   while ( lowerNumber < higherNumber ) {
     System.out.println( lowerNumber );
     lowerNumber++;
   }
Member
Posts: 2,869
Joined: Aug 6 2012
Gold: 4.00
Jun 25 2013 08:06am
Quote (labatymo @ Jun 25 2013 10:02pm)
Code
System.out.println( "Enter number 1: " );
   int num1 = new Scanner( System.in ).nextInt( );
   System.out.println( "Enter number 2: " );
   int num2 = new Scanner( System.in ).nextInt( );
   int higherNumber;
   System.out.println( "Highest number: "
       + (higherNumber = (num1 > num2) ? num1 : num2) );
   int lowerNumber = (num1 == higherNumber) ? num2 : num1;
   while ( lowerNumber < higherNumber ) {
     System.out.println( lowerNumber );
     lowerNumber++;
   }


i need the algorithm of this before giving u the fg.
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Jun 25 2013 12:12pm
Quote (Yappie @ Jun 25 2013 09:06am)
i need the algorithm of this before giving u the fg.


You're a damn idiot, is this day 1 of your class?

if number1 > number2 (
variable = number2
highernumber = number1
for number2 to number 1(
output = output + str(variable)
variable++
)
)

If you can't do this I would seriously consider dropping your class.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 25 2013 04:42pm
Quote (Yappie @ Jun 25 2013 10:06am)
i need the algorithm of this before giving u the fg.


what do you think the word algorithm means? similarly, what do you think it looks like?
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Jun 26 2013 11:32am
Quote (Yappie @ Jun 25 2013 07:06am)
i need the algorithm of this before giving u the fg.


:wacko:
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll