its 2am!l lol an i have class in a couple ah hours.
Code Java:
public static int nextLarger (int num, int n){ while (num != 0) { } }
--- Update ---
what's next?
Printable View
its 2am!l lol an i have class in a couple ah hours.
Code Java:
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 :)
Code Java:
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 typeQuote:
temp=0;
apology, please make the answer equal to the maximum value, int answer = Integer.MAX_VALUE;Quote:
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.
Code Java:
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
Code Java:
--- 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"
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.
Code Java:
--- Update ---
No has an error when calling the function in main
no, it should be temp less than answer.Quote:
if (answer <temp)
that was before the loop ends, that should be division not modulo..Quote:
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)Quote:
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.Quote:
nextLarger(num,n);
--- Update ---
no, it should be temp less than answer.Quote:
if (answer <temp)
that was before the loop ends, that should be division not modulo..Quote:
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.Quote:
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.Quote:
num= num% 10;
you used num and n, but not initialize them,Quote:
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.
Code Java:
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
you used printf in a wrong way. I think it is better for you to just use println instead of printfQuote:
System.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 fileQuote:
FileReader in = new FileReader ("passage.txt");
Can you post the new version of the code?
Code Java:
errors:
PrintWriter.format(String, Object...) line: 908
PrintWriter.printf(String, Object...) line: 804
Format.main(String[]) line: 32
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.
See if this helps:
Code :
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