Getting Input from User in Java
package com.company;
import java.util.Scanner;
public class userinput {
public static void main(String[] args) {
// how to take input from keyboard
// System.out.println("Taking Input From The User");
// Scanner sc = new Scanner(System.in);
// System.out.println("Enter number 1");
// int a = sc.nextInt();
// System.out.println("Enter number 2");
// int b = sc.nextInt();
// int sum = a + b;
// System.out.println("The Sum Of These numbers is");
// System.out.println(sum);
// System.out.println("Taking Input From The User for percentage");
// System.out.println("Enter number 1");
// float c = sc.nextFloat();
// System.out.println("Enter number 2");
// float d = sc.nextFloat();
// float percentage = (c /d)*100;
// System.out.println("The Percentage Of These numbers is");
// System.out.println(percentage);
//check if next an integer is filled by the user
// System.out.println("Taking Input From The User 2");
// System.out.println("Enter number 1");
// boolean b1 = sc.hasNextInt();
// System.out.println(b1);
//How to read 1st word
System.out.println("Taking Input From The User 3");
Scanner sc = new Scanner(System.in);
// String str = sc.next();
// System.out.println(str);
//How to read line
String str = sc.extLine();
System.out.println(str);
}
}
Comments
Post a Comment