Java Program - Write a java program how to take input from a user.
Enter an integer value ::
100
Entered integer value :: 100
Enter a float value ::
2.0
Entered float value :: 2.0
Enter a string ::
Study Viral
Entered string :: Study Viral
//Java Program - 06 - Write a java program how to take input from a user. import java.util.Scanner; public class StudyViral_06 { public static void main(String[] args) { int var1; float var2; String var3; Scanner sc = new Scanner(System.in); System.out.println("Enter an integer value :: "); var1 = sc.nextInt(); System.out.println("Entered integer value :: "+var1); System.out.println("Enter a float value :: "); var2 = sc.nextFloat(); System.out.println("Entered float value :: "+var2); sc.nextLine();//This statement is required to //read empty Enter key stroke after float value System.out.println("Enter a string :: "); var3 = sc.nextLine(); System.out.println("Entered string :: "+var3); } }
Output ::
Enter an integer value ::
100
Entered integer value :: 100
Enter a float value ::
2.0
Entered float value :: 2.0
Enter a string ::
Study Viral
Entered string :: Study Viral
0 comments:
Post a Comment