its 2am!l lol an i have class in a couple ah hours.
public static int nextLarger (int num, int n){ while (num != 0) { } }
--- Update ---
what's next?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
its 2am!l lol an i have class in a couple ah hours.
public static int nextLarger (int num, int n){ while (num != 0) { } }
--- Update ---
what's next?
good. then before the while loop create a int variable whose value is zero. we are going to put the answer on that variable.
then inside the loop create int variable whose value is num module by 10, num % 10.
after that we are now on 50% of your activity
Last edited by dicdic; March 21st, 2014 at 01:05 AM.
public static int nextLarger (int num, int n){ int answer=0; temp=0; while (num != 0) { temp=num%10; } }
good, but put int keyword before temp variable, that is the data typetemp=0;
apology, please make the answer equal to the maximum value, int answer = Integer.MAX_VALUE;int answer=0;
next inside the loop after the modulo part.
create a if condition whose condition is temp greater than n.
then inside that condition create another if condition whose condition is answer less than temp.
public static int nextLarger (int num, int n){ int answer=Integer_MAX VALUE; int temp=0; while (num != 0) { temp=num%10; if (temp>n) { if (answer <temp) { } } } }
then inside the if (answer <temp) make your answer variable equal to temp.
and before the loop ends, make your num equal to num divided by 10.
then your can test the method with public static void main method.. that will work
--- Update ---
and after the loop, return the answer variable
--- Update ---
I am having trouble linking the method the main
errors: "smallest cannot be resolved as variable"
and for the method
error: "the method must return a result of type int"
Last edited by Java girl; April 13th, 2014 at 03:52 PM.
there is one error after compiling it.
System.out.printf("%d ",nextLarger(smallest));
the argument shoud be num and n, nextLarger(num, n)
and please return the answer after the loop.
--- Update ---
No has an error when calling the function in main
Last edited by Java girl; April 13th, 2014 at 03:52 PM.
no, it should be temp less than answer.if (answer <temp)
that was before the loop ends, that should be division not modulo..num= num% 10;
and please remove the while loop in main method for now,, and test it,,
--- Update ---
and make your answer equal to nextLarger(num,n);
then print the answer
--- Update ---
please modify that, if(temp < answer)if (answer <temp)
because you did not initialize the variable, by default you better make int num = 0 and n = 1;
just print that, or make your answer variable in main equal to that.nextLarger(num,n);
--- Update ---
no, it should be temp less than answer.if (answer <temp)
that was before the loop ends, that should be division not modulo..num= num% 10;
and please remove the while loop in main method for now,, and test it,,
--- Update ---
and make your answer equal to nextLarger(num,n);
then print the answer
--- Update ---
if (answer <temp)
no, it should be temp less than answer.
num= num% 10;
that was before the loop ends, that should be division not modulo..
and please remove the while loop in main method for now,, and test it,,
--- Update ---
and make your answer equal to nextLarger(num,n);
then print the answer
--- Update ---
if (answer <temp)
please modify that, if(temp < answer)
because you did not initialize the variable, by default you better make int num = 0 and n = 1;
nextLarger(num,n);
just print that, or make your answer variable in main equal to that.
--- Update ---
it should be division not modulo.num= num% 10;
you have a loop in your main that uses num and n as condition, then you must initialize a value for them
it is better to put a value to n that is greater than num.
int num = 0, n = 1;
it works great but i still have probs joinin the 2 without an error
--- Update ---
ok i got the error off , thanks a million!!!! can u check another for me? i already did it
it should be division not modulo.num= num% 10;
you used num and n, but not initialize them,int num,n,answer;
while (num>n)
{
you better declare them as int num = 0, n = 1;
make n equals 1 so the condition in loop will be true
--- Update ---
sure
--- Update ---
please check the output first, print it. so you can see it really works
This was the given question:
Write a Java program Format.java, to read a passage from an input file passage.txt and
print to another file newPassage.txt the same passage with the following changes:
Each sentence should be printed on a new line.
All numbers should be removed.
The program should also keep track of and print (to the same file) how many times each
vowel appears.
This is my solution but its gettin an error
--- Update ---
This was the error:
Exception in thread "main" java.util.IllegalFormatCodePointException: Code point = 0xffffffff
at java.util.Formatter$FormatSpecifier.printCharacter (Formatter.java:2819)
at java.util.Formatter$FormatSpecifier.print(Formatte r.java:2712)
at java.util.Formatter.format(Formatter.java:2488)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at assignment3Quest1.Format.main(Format.java:26)
maybe somewhere in my program there is not a constant flow
Last edited by Java girl; April 13th, 2014 at 03:51 PM.
you used printf in a wrong way. I think it is better for you to just use println instead of printfSystem.out.printf("Count of vowel: a or A" + "=" + countVowel1);
are you sure that is the error message?
in that code it will throws an exception of file not found. the parameter must either be the full path of the file or the parent path of java file and the fileFileReader in = new FileReader ("passage.txt");
Can you post the new version of the code?
If you don't understand my answer, don't ignore it, ask a question.
errors:
PrintWriter.format(String, Object...) line: 908
PrintWriter.printf(String, Object...) line: 804
Format.main(String[]) line: 32
Last edited by Java girl; April 13th, 2014 at 03:51 PM.
Please copy the full text of the error messages and paste it here.
What you have posted does not say what the errors are.
And the line numbers: (908 and 804) are not in your program.
If you don't understand my answer, don't ignore it, ask a question.
See if this helps:
import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public class Format { public static void main(String[] args) throws IOException { // FileReader in = new FileReader ("passage.txt"); PrintWriter out = new PrintWriter(new FileWriter("newPassage.txt")); int currCh; int countVowel1 =0, countVowel2=0, countVowel3=0, countVowel4=0, countVowel5=0; while ( (currCh = in.read()) != -1)//not end of file { System.out.println((char)currCh); if (currCh == '.') // full stop indicates a new line so print on new line { out.write(".\n"); continue; } else if (currCh != '\n' && currCh != '\r' && currCh != '0' && currCh !='1'&& currCh != '2' && currCh !='3' && currCh != '4' && currCh !='5'&& currCh != '6'&& currCh !='7'&& currCh != '8' && currCh !='9') { out.write((char)currCh); //after passage with skipped lines and removed numbers is printed //check check begins if(currCh =='a' || currCh =='A') { countVowel1++; } else if(currCh =='e' || currCh == 'E') { countVowel2++; } else if(currCh =='i' || currCh == 'I') { countVowel3++; } else if(currCh =='o' || currCh == 'O') { countVowel4++; } else if(currCh =='u' || currCh == 'U') { countVowel5++; } } }//end while System.out.println("Count of vowel: a or A" + "=" + countVowel1); //outputs vowel count for each vowel System.out.println("Count of vowel: e or E" + "=" + countVowel2); System.out.println("Count of vowel: i or I" + "=" + countVowel3); System.out.println("Count of vowel: o or O" + "=" + countVowel4); System.out.println("Count of vowel: u or U" + "=" + countVowel5); in.close(); out.flush(); out.close(); }//end main} }//end program
@dev73 Please read: http://www.javaprogrammingforums.com...n-feeding.html
If you don't understand my answer, don't ignore it, ask a question.