0% found this document useful (0 votes)
14 views2 pages

Case Study 3

The document contains 3 Java code snippets that take user input and perform operations. The first takes two numbers as input and prints the larger number. The second takes a word as input and prints its length. The third takes a single character numeric input inside a loop, validating the input is a digit.

Uploaded by

FrancisPlays
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Case Study 3

The document contains 3 Java code snippets that take user input and perform operations. The first takes two numbers as input and prints the larger number. The second takes a word as input and prints its length. The third takes a single character numeric input inside a loop, validating the input is a digit.

Uploaded by

FrancisPlays
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

package Final;
import java.util.*;

public class Main {

public static void main(String[] args) {


Scanner x = new Scanner(System.in);
System.out.print("Input Two Numbers: ");
int n1 = x.nextInt();
int n2 = x.nextInt();

int max = Math.max(n1, n2);


System.out.println(“Largerst Number” + max);
}

2. package Final;
import java.util.*;

public class Main {

public static void main(String[] args) {


Scanner x = new Scanner(System.in);
System.out.print("Please enter a word: ");
String word = x.nextLine();
System.out.println("Your word has " + word.length() + " characters.");
}

}
3. package Final;
import java.util.*;

public class Main {

public static void main(String[] args) {


Scanner x = new Scanner(System.in);

while (true)
{
System.out.print("Please enter a number: ");
String input = x.next();
if (!Character.isDigit(input.charAt(0)))
{
if (input.length() >= 2)
{
System.out.println("Please enter 1 character only");
System.out.println();
}
else
{
System.out.println("Oops! That's not a Digit");
System.out.println();
}
}
else
{
System.out.println("Thanks!");
System.out.println();
}
}
}

You might also like