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.

Results 1 to 5 of 5

Thread: java integers

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default java integers

    hi again to all i need to do this exercises
    i am not good at java but i have to deliver them so
    there they are , can someone help me
    thanks

    EXERCISE 1
    Write a java program that receives the keyboard two integers and
    shows the result of dividing the first of the latter.
    ; If the values are not corresponding to integers appear appropriate message,
    after handling the exception NumberFormatException.
    ; If the division can not be done because the denominator is equal to zero, be
    Handling ArithemticException and appears suitable message.


    EXERCISE 2

    write a program java, using headings File, FileReader and FileWriter to do
    the following:
    1. Examine whether the file src.txt is the current directory. If there should be
    terminates the execution of using the exception FileNotFoundException.
    2. Copies the contents of the file src.txt dest.txt, adding a blank line after
    each line src.txt plus replacing all spaces with the @ character.
    3. Finally, it displays the size in bytes of the file and src.txt dest.txt, both before the opening as
    after closing the file.

  2. The Following User Says Thank You to timeline For This Useful Post:

    lucasantos (April 20th, 2010)


  3. #2
    Junior Member
    Join Date
    Apr 2010
    Location
    Italy
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default Re: java integers

    Hy, this is the my solution for Exercise 1.
    If u don't specify 2 input, in console u find "I need 2 input as parameters";
    If the input aren't integer, the message will be "Inputs have to be integer";
    If the second input is 0, the message will be "Is not possible divide by zero"
    public class exe1 {
        public static void main(String[] args) {
            if (args.length<2) {
                System.err.println("I need 2 input as parameters");
            }else{
                int a;
                int b;
                try{
                    // I'm tring to convert the first input
                    a = Integer.parseInt(args[0]);
                    // I'm tring to convert the second input
                    b = Integer.parseInt(args[1]);
     
                    System.out.println("The result is: " + (a/b));
     
                }catch(NumberFormatException e){
                    System.err.println("Inputs have to be integer");
                }catch(ArithmeticException e){
                    System.err.println("Is not possible divide by zero");
                }    
     
            }
        }
     
    }

  4. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: java integers

    thx for the help

  5. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: java integers

    we don't do other people's assignments for them on this forum. Timeline, please show us what effort you've made to solve the problem and we will help you figure out what's not working correctly.

  6. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: java integers

    its ok you r right thanx anyway

Similar Threads

  1. [SOLVED] Writing integers to a file
    By dubois.ford in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 15th, 2010, 07:18 PM
  2. Replies: 5
    Last Post: May 21st, 2009, 03:45 AM
  3. [SOLVED] Java program to convert and compare integers
    By luke in forum What's Wrong With My Code?
    Replies: 9
    Last Post: May 18th, 2009, 07:26 PM