Answers for "accept string from user in java"

14

taking string input in java

Scanner in = new Scanner(System.in);
String s = in.nextLine();
Posted by: Guest on April-27-2020
0

java program to accept user input

import java.util.Scanner;

class GetInputData
{
  public static void main(String args[])
  {
     int num;
     float fnum;
     String str;
 
     Scanner in = new Scanner(System.in);
 
     //Get input String
     System.out.println("Enter a string: ");
     str = in.nextLine();
     System.out.println("Input String is: "+str);
 
     //Get input Integer
     System.out.println("Enter an integer: ");
     num = in.nextInt();
     System.out.println("Input Integer is: "+num);
 
     //Get input float number
     System.out.println("Enter a float number: ");
     fnum = in.nextFloat();
     System.out.println("Input Float number is: "+fnum); 
  }
}
Posted by: Guest on September-23-2021

Code answers related to "accept string from user in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language