Results 1 to 11 of 11
  1. #1
    Jhaddoush is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Unhappy what after converting from char to double??

    Hello..

    I don't know that to do after converting form char to double??

    char rate;
    double c = rate;

    How can i write the input code??

    i tried :
    rate = keyboard.next();
    rate = keyboard.nextDouble();

    but nothing worked!! :(

    what is the correct code for it?!!

  2. #2
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: what after converting from char to double??

    what do you want to with the program? do you want input from the user?

    make sure to import
    Java Code:
    import java.util.Scanner;
    and make sure make a new scanner like:
    Java Code:
    Scanner input = new Scanner (System.in);
    here is your example:

    Java Code:
    import java.util.Scanner;
    public class example {
    	public static void main(String args[]){
    		Scanner input = new Scanner (System.in);
    		double rate;
    		rate = input.nextDouble();
    		
    	}
    
    }

    i hope this is what you meant
    Last edited by MR bruto; 05-03-2013 at 09:41 PM.

  3. #3
    Jhaddoush is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default Re: what after converting from char to double??

    I did that what after converting from char to double??-screen-shot-2013-05-03-9.50.18-pm.png


    I'm converting from char to double because my input will be a percentage
    but i only need the number without the % symbol to calculate the returns.
    Attached Thumbnails Attached Thumbnails what after converting from char to double??-screen-shot-2013-05-03-9.41.45-pm.png  
    Last edited by Jhaddoush; 05-03-2013 at 09:51 PM.

  4. #4
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: what after converting from char to double??

    alright, but why do you even make that "rate" thing? that char?
    just make it
    Java Code:
    double rate;
    or
    Java Code:
    int rate;

  5. #5
    Jhaddoush is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default Re: what after converting from char to double??

    My input will be a percentage like: 5%
    but i need to use that 5 in my calculation...

    import java.util.Scanner;
    import java.lang.Character;
    public class Returns {
    public static void main(String[] args){
    char rate;
    double amount, returns, c=rate;
    int syear, eyear;
    Scanner keyboard = new Scanner(System.in);
    System.out.println("Please, Enter the amount of the money:");
    amount = keyboard.nextDouble();
    System.out.println("Please, Enter the percenge rate number:");
    rate = keyboard.next();
    System.out.println("Please, The starting year:");
    syear = keyboard.nextInt();
    System.out.println("Please, The ending year:");
    eyear = keyboard.nextInt();

    if (syear>eyear)
    {
    System.out.println("The return is 0");
    }
    if (amount < 0){
    System.out.println("The return is 0");
    }
    else {
    returns = (c*amount)/100 * (eyear-syear)+ amount;
    System.out.println("The returns: "+returns);
    }
    }

    }

  6. #6
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: what after converting from char to double??

    i dont really think that you have to make rate a char.
    try to make it a double and check if it works

  7. #7
    Jhaddoush is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default Re: what after converting from char to double??

    what after converting from char to double??-screen-shot-2013-05-03-10.48.40-pm.png


    :(

  8. #8
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: what after converting from char to double??

    why do you fill in "5%" ???
    when you ask someone the percentage number, you can just enter 5 lol.

  9. #9
    Jhaddoush is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default Re: what after converting from char to double??

    I think i will do it like that :D

    But for sure there is a way to solve it and i wanna know it :D

  10. #10
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: what after converting from char to double??

    indeed :) there must be a way to solve it, but im still a beginner and this was 1 solution for the problem.

    enjoy

  11. #11
    Jhaddoush is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default Re: what after converting from char to double??

    Thank you very much for helping <3

Similar Threads

  1. char to double
    By shred in forum New To Java
    Replies: 11
    Last Post: 09-26-2012, 12:44 AM
  2. Quick Question regarding converting char to String
    By StormyWaters in forum New To Java
    Replies: 1
    Last Post: 09-06-2012, 12:05 AM
  3. Converting double to char array?
    By Blasz in forum New To Java
    Replies: 9
    Last Post: 08-29-2010, 08:32 PM
  4. Converting a char to an int
    By michail in forum New To Java
    Replies: 10
    Last Post: 01-06-2010, 10:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •