0

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));
   }
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Software guy
0

hi,
i think you are already getting the String in to the Character, but you should replace

d.charAt(0);

with

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.