Computer Science, asked by hhtyyg, 1 year ago

Write a program (using scanner class) to input a line and display only numeric tokens.
Sample Input : 26 January 1950 is celebrated as Republic day
Sample output : 26 1950

Answers

Answered by Anonymous
7

//To display only numeric tokens present in a line

import java.util.Scanner;

public class NumToken

{

//main method to test Scanner Class

public static void main(String[] args)

  {

   System.out.println("Enter line ending with a space & terminate with (.) :");

   Scanner in=new Scanner(Sytem.in);

   while(true)

       {

       if(in.hasNextInt());

       System.out.print(in.nextInt()+" ");

       if(in.next().equals("."))

       break;

        }

    }

}


annesha43: stiok
Answered by aryan2403m
0

Explanation:

import java.util.*;

public class Token

{

public status void main (String () args)

{

System.out.Printing("Enter line ending with a space & terminating with (.) :");

Scanner sc = new Scanner(System.In);

while(true)

{

if(in.hasNextInt())

System.out.Print on(in.nextInt()+" ");

if(in.next().equals("."))

break;

}

}

}

Similar questions