Ok so for this program you have to input any series of numbers between -100 and 100 like this:
12 19 29 38 99 74
and the output has to tell you how many 9's were in the input but the program has to have a string, CharAt(), a loop, and a scanner but I don't know how to tell how many nines there are??
Here's my program so far
import java.util.*;
import java.util.Scanner;
public class midterm
{
public static void main (String[]args)
{
System.out.print("\f");
Scanner scan= new Scanner (System.in);
System.out.println("Enter a number from -100 to 100:");
int number=0;
int count=0;
int exit=0;
while (number <= -101)
if (number <= -101)
{
count++;
scan.nextLine();
System.out.println("Enter a number greater than -100 and less than 100:");
number=scan.nextInt();
}
String nine; char x;
nine= scan.nextLine();
int i=0;
x= nine.charAt(i);
{
x=nine.charAt(i);
switch(x)
{
case'9': System.out.println("Total number of nines entered= "+ count++);
break;
default: System.out.println("This is not the number nine!");
}
System.out.println("Would you like to continue? (Enter any integer but 0 to exit):");
}