Page 128 - CA_Blue( J )_Class9
P. 128
6.5.6 nextFloat() Method
It is used to read a float value (real number) and returns token as a float value. For example, to accept a real
number:
float f= sc.nextFloat();
6.5.7 nextDouble() Method
It is used to read a double value (real number) and returns token as a double value. For example, to accept a real
number:
double d= sc.nextDouble();
6.5.8 next().charAt(0) Method
It is used to read a complete string and returns a character value. The next() is used to read a string value and
charAt(0) extracts the character and store in a variable. For example, to extract a character:
char c= sc.next().charAt(0);
Write a Java program to input two numbers and print the numbers after swapping. For
Program 6
example:
Input a=8, b=4
Output a=4, b=8
1 import java.util.*;
2 class swapping
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 int a,b,temp;
8 System.out.println("Enter two numbers ");
9 a=sc.nextInt();
10 b=sc.nextInt();
11 System.out.println("Before Swapping : "+ a+" "+b);
12 temp = a;
13 a=b;
14 b=temp;
15 System.out.println("After Swapping : "+ a+" "+b);
16 }
17 }
126 Touchpad Computer Applications-IX

