Results 1 to 11 of 11
Thread: i really need ur help guys.
- 10-19-2012, 08:22 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 10
- Rep Power
- 0
i really need ur help guys.
hi guys.
can u please help me in my project?
i need a code for a java program that accepts input number and displays the largest among the individual digits of that input.
The sample output is here.
Input Number: 1234569822
Largest Digit: 9
We cant still use arrays guys because we didnt discuss it yet.
Hope u can help me with this.
for loop,while loop can do
thanks.
- 10-19-2012, 08:26 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: i really need ur help guys.
Do you know how to find the least significant digit of a number? e.g. for the number 12345, the least significant digit is 5.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-19-2012, 08:31 AM #3
Member
- Join Date
- Oct 2012
- Posts
- 10
- Rep Power
- 0
Re: i really need ur help guys.
my bad.
im really new to programming.
i dont really know.
hope u can help me
- 10-19-2012, 08:45 AM #4
Member
- Join Date
- Oct 2012
- Location
- Tempe, Arizona
- Posts
- 77
- Blog Entries
- 12
- Rep Power
- 0
Re: i really need ur help guys.
Hint: It involves modulus and the base of the number format you are using...
Catching exceptions is for communists
- 10-19-2012, 08:47 AM #5
Member
- Join Date
- Oct 2012
- Posts
- 10
- Rep Power
- 0
Re: i really need ur help guys.
can u help me with the code?
im really new to java programming,
^_^
- 10-19-2012, 08:50 AM #6
Member
- Join Date
- Oct 2012
- Location
- Tempe, Arizona
- Posts
- 77
- Blog Entries
- 12
- Rep Power
- 0
Re: i really need ur help guys.
What did you have completed? Do you know how modulus works?
I can help you with the code, but I'm not going to write it all for you.Catching exceptions is for communists
- 10-19-2012, 08:56 AM #7
Member
- Join Date
- Oct 2012
- Posts
- 10
- Rep Power
- 0
Re: i really need ur help guys.
modulu sounds familiar but im going to check it.
i really need ur help with this because im failing this subject.
- 10-19-2012, 09:02 AM #8
Member
- Join Date
- Oct 2012
- Location
- Tempe, Arizona
- Posts
- 77
- Blog Entries
- 12
- Rep Power
- 0
Re: i really need ur help guys.
Just break it down into more manageable sections. Rather then thinking about the entire project, think of it as four parts.
A)Gather input from the user
Using println() methods and the Scanner object.
B)Perform math on the user input
Using modulus (%), you can find the remainder.
C)Perform some type of comparison to find the largest single digit number
You could do this while doing the math, to save on variables, or save them all and do it later.
D)Output the answer to the user
Modulus is a tool that is used to find the remainder after a division occurs. Say you have 12/5, the answer would be 5 with 2 left over. If you used modulus, 12%5, the answer would be just the 2 left over. You can use this to find the least signigicant digit in a larger number. Say you have 25, and you wanted just the 5. Well since digits are base 10, you can just take the modulus of 25, 25%10, and you are just left with the 5.Catching exceptions is for communists
- 10-19-2012, 09:09 AM #9
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: i really need ur help guys.
Now also appearing at javaprogrammingforums.com
@OP: If you are going to start a discussion in multiple places, please post links in each to the others. That way all the participants in the discussion know what else is being said.
And it is a discussion: questions, replies, comments, thoughts and reflections - all occurring in both directions. What it is *not* is a homework service. Not here, and not at javaprogrammingforums.
---
Have you thought about the problem? If so, it would be good to hear how you yourself (rather than a computer) would go about determining that 9 was the largest digit as you stated. Such a procedure (or algorithm) would form the basis of your code.
Look up the modulus or remainder operator (%) and find out how it relates to the least significant digit. Try and incorporate that into your algorithm (recipe) for determining the largest digit, and let us know how you get on.Last edited by pbrockway2; 10-19-2012 at 09:12 AM.
- 10-19-2012, 09:09 AM #10
Member
- Join Date
- Oct 2012
- Posts
- 10
- Rep Power
- 0
Re: i really need ur help guys.
how about i want to input random numbers?
- 10-19-2012, 10:35 AM #11
Member
- Join Date
- Oct 2012
- Posts
- 10
- Rep Power
- 0
Re: i really need ur help guys.
import java.util.Scanner;
class group{
public static void main(String arng[]){
int value[]= new int[5];
int temp,i;
Scanner data = new Scanner(System.in);
System.out.println("Enter 5 element of array" );
// Enhanced for loop
for(i=0; i < 5; i++ ) value[i] = data.nextInt();
// finding Largest number
temp = value[0];
for(i=0; i < 5; i++ )
{
if(temp > value[i])
continue;
else
temp = value[i];
}
System.out.println("Largest number in array is "+temp);
}
}
Output:-
Enter 5 element of array
25
154
28522
218
2564
Largest number in array is 28522
i tried this but how can i do it without arrays?
and in a single 10 digits input how can i get the largest?
like 9899823211
how can i get 9?
Similar Threads
-
Hello guys
By RamaAditya in forum IntroductionsReplies: 2Last Post: 09-24-2011, 06:02 PM -
hey, guys
By yvangkwheng in forum IntroductionsReplies: 1Last Post: 03-11-2010, 09:02 AM -
Hey guys!
By Syntax in forum IntroductionsReplies: 0Last Post: 01-15-2010, 08:58 PM -
hi guys
By jackson787 in forum Reviews / AdvertisingReplies: 0Last Post: 01-12-2010, 06:19 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks