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

Thread: String handling

  1. #1
    Junior Member
    Join Date
    Aug 2022
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool String handling

    Can anyone write an essay on the following program

    import java.util.*;
    public class calc
    {
    int i,p,k=0;
    double o=0, a=0;
    String operation="", fin1;
    void input()
    {
    Scanner in= new Scanner(System.in);
    System.out.println("Enter the first number");
    i= in.nextInt();
    System.out.println("Enter the second number");
    p= in.nextInt();
    System.out.println("Enter the operation");
    operation= in.nextLine();
    }

    void calculate()
    {
    if(operation.equalsIgnoreCase("Add"))
    {
    k=i+p;
    fin1= "The sum of "+i+" and "+p+" is: "+k;
    }
    else if(operation.equalsIgnoreCase("Minus"))
    {
    k=i-p;
    fin1= "The difference of "+i+" and "+p+" is: "+k;
    }
    else if(operation.equalsIgnoreCase("Multiply"))
    {
    k=i*p;
    fin1= "The answer when "+i+" and "+p+" are multiplied is: "+k;
    }
    else if(operation.equalsIgnoreCase("Divide"))
    {
    k=i/p;
    fin1= "The answer when "+i+" and "+p+" are divided is: "+k;
    }
    else if(operation.equalsIgnoreCase("Remainder"))
    {
    k=i%p;
    fin1= "The remainder when "+i+" and "+p+" are divided is: "+k;
    }else if(operation.equalsIgnoreCase("Percent"))
    {
    k=i*100/p;
    fin1= "The percentage of "+i+" and "+p+" is: "+k;
    }
    else if(operation.equalsIgnoreCase("Random"))
    {
    if(i>=1&&p<=10)
    {
    o=Math.random()*10;
    fin1= "The random value between 1-10 is: "+o;
    }
    else if(i>=10&&p<=20)
    {
    o=Math.random()*100;
    fin1= "The random value between 10-20 is: "+o;
    }
    else
    {
    o=0.0;
    fin1= "ErrOR";
    }
    }
    else if(operation.equalsIgnoreCase("sqrt"))
    {
    o= Math.sqrt(i);
    a= Math.sqrt(p);
    fin1="The square root of "+i+" is ("+o+") and the square root of "+p+" is ("+a+")";
    }
    else if(operation.equalsIgnoreCase("cbrt"))
    {
    o= Math.cbrt(i);
    a= Math.cbrt(p);
    fin1="The cube root of "+i+" is ("+o+") and the cube root of "+p+" is ("+a+")";
    }
    }

    void display()
    {
    System.out.println("The first number: "+i);
    System.out.println("The second number: "+p);
    System.out.println(" ");
    System.out.println(fin1);
    }

    static void main()
    {
    calc sc= new calc();
    sc.input(); sc.calculate(); sc.display();
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: String handling

    write an essay
    Please explain what you are looking for.
    What have you tried?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. string handling
    By shilpy in forum What's Wrong With My Code?
    Replies: 8
    Last Post: September 24th, 2014, 12:54 PM
  2. Replies: 1
    Last Post: April 19th, 2012, 02:46 AM
  3. Need help with exception handling for a string
    By toppcon in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 6th, 2011, 06:59 AM
  4. Output String Handling in Java
    By merry in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 21st, 2010, 09:59 PM
  5. Exception handling
    By AnithaBabu1 in forum Exceptions
    Replies: 6
    Last Post: August 27th, 2008, 09:37 AM