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));
   }

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.