Answers for "scan number not int java"

1

how to scan Integer in Java

import java.util.*;
public class HowToScan {
   public static void main( String args[] ) 
   {
      Scanner S = new Scanner(System.in);
      int a;
      int b;
      int sum;
        a = S.nextInt();
        b = S.nextInt();
        	sum = a + b;
        System.out.println( a + "+" + b  + "=" + sum );
   }
}
Posted by: Guest on March-25-2021
0

java to check if its a number scanner

Scanner sc = new Scanner(System.in);
int number;
do {
    System.out.println("Please enter a positive number!");
    while (!sc.hasNextInt()) {
        System.out.println("That's not a number!");
        sc.next(); // this is important!
    }
    number = sc.nextInt();
} while (number <= 0);
System.out.println("Thank you! Got " + number);
Posted by: Guest on August-25-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language