943,864 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 10027
  • Java RSS
Jul 17th, 2008
0

setting a string to a char

Expand Post »
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));
   }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JConnor135 is offline Offline
18 posts
since Jul 2008
Jul 17th, 2008
0

Re: setting a string to a char

hi,
i think you are already getting the String in to the Character, but you should replace
Java Syntax (Toggle Plain Text)
  1. d.charAt(0);
with
Java Syntax (Toggle Plain Text)
  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.
Reputation Points: 16
Solved Threads: 18
Junior Poster
Software guy is offline Offline
151 posts
since May 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: button listener question
Next Thread in Java Forum Timeline: Problem: Instant Messenger





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC