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.

Page 2 of 2 FirstFirst 12
Results 26 to 44 of 44

Thread: Please help me

  1. #26
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

    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?

  2. #27
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    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.

  3. #28
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

    public static int nextLarger (int num, int  n){
          int answer=0;
          temp=0;
     
          while (num != 0)
          {    
              temp=num%10;
     
         }
    }

  4. #29
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    temp=0;
    good, but put int keyword before temp variable, that is the data type

    int answer=0;
    apology, please make the answer equal to the maximum value, int answer = Integer.MAX_VALUE;

    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.

  5. #30
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

    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)
                  {
     
                  }
     
               }
         }
    }

  6. #31
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    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

  7. #32
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

     


    --- 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.

  8. #33
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    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.

  9. #34
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

     


    --- Update ---

    No has an error when calling the function in main
    Last edited by Java girl; April 13th, 2014 at 03:52 PM.

  10. #35
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    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 ---

    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)
    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 ---

    num= num% 10;
    it should be division not modulo.

    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;

  11. #36
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

    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

  12. #37
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    num= num% 10;
    it should be division not modulo.

    int num,n,answer;
    while (num>n)
    {
    you used num and n, but not initialize them,
    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

  13. #38
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

    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.

  14. #39
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    System.out.printf("Count of vowel: a or A" + "=" + countVowel1);
    you used printf in a wrong way. I think it is better for you to just use println instead of printf


    are you sure that is the error message?
    FileReader in = new FileReader ("passage.txt");
    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 file

  15. #40
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help me

    Can you post the new version of the code?
    If you don't understand my answer, don't ignore it, ask a question.

  16. #41
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Please help me

     



    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.

  17. #42
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help me

    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.

  18. #43
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me

    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

  19. #44
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help me

    @dev73 Please read: http://www.javaprogrammingforums.com...n-feeding.html
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12