setting a string to a char

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2008
Posts: 18
Reputation: JConnor135 is an unknown quantity at this point 
Solved Threads: 0
JConnor135 JConnor135 is offline Offline
Newbie Poster

setting a string to a char

 
0
  #1
Jul 17th, 2008
for this code I need to set string d to char c, can anyone tell me how to do it?

public static void main(String[] args)
  {
    int n;
    int m;
    String d;
    char c;
    
    Scanner sc = new Scanner(System.in);
    
    System.out.println("Input Integer: ");
    
    //get the value
    n=sc.nextInt();
    
    int answer = sum_upto(n);
    
    System.out.println("sum of numbers from 1 to n: " + answer);
    
    System.out.println("input a character and two integers: ");
    
    //get the values
    d=sc.next();
    n=sc.nextInt();
    m=sc.nextInt();
    d.charAt(0);
    
    
    System.out.println(writeBlock(c, m, n));
   }
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 38
Reputation: Software guy is an unknown quantity at this point 
Solved Threads: 2
Software guy Software guy is offline Offline
Light Poster

Re: setting a string to a char

 
0
  #2
Jul 17th, 2008
hi,
i think you are already getting the String in to the Character, but you should replace
  1. d.charAt(0);
with
  1. c = d.charAt(0);
Thats it really , as we already know that String is like an array of characters. So according to my understanding you are right.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC