4 Replies - 195 Views - Last Post: 12 June 2019 - 12:55 AM Rate Topic: -----

#1 count1010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-June 19

How would I change the output to a string?

Posted 10 June 2019 - 06:47 PM

Let's say you input 'P' or 'p' and I want the output to say Premium.
import java.util.Scanner; 
public class ScannerDemo1 
{ 
    public static void main(String[] args) 
    { 
        // Declare the object and initialize with 
        // predefined standard input object 
        Scanner sc = new Scanner(System.in); 
   
        // Character input 
        char p = sc.next().charAt(0); 
   
        // Print the read value 
        System.out.println("Type = "+p); 
    } 
}


Is This A Good Question/Topic? 0
  • +

Replies To: How would I change the output to a string?

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15116
  • View blog
  • Posts: 60,494
  • Joined: 12-June 08

Re: How would I change the output to a string?

Posted 10 June 2019 - 06:50 PM

Please add a question.
Was This Post Helpful? 0
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 617
  • View blog
  • Posts: 4,113
  • Joined: 12-January 10

Re: How would I change the output to a string?

Posted 11 June 2019 - 10:28 AM

you would need to create an array or list that contains said strings then search through the list for the item. then do what ever you need to convert it to what ever you want
Was This Post Helpful? 0
  • +
  • -

#4 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,842
  • Joined: 25-December 13

Re: How would I change the output to a string?

Posted 11 June 2019 - 12:58 PM

A couple of ways to map a single letter to a String:
Use a Map<String, String>
Use a switch statement
Was This Post Helpful? 0
  • +
  • -

#5 Atspulgs   User is offline

  • D.I.C Addict

Reputation: 100
  • View blog
  • Posts: 537
  • Joined: 29-July 09

Re: How would I change the output to a string?

Posted 12 June 2019 - 12:55 AM

String.valueOf()
:rockon:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1