1. Ask of a specific String
2. The array will only contain integral values
3. Display the length of the original String
4. Display the length of the array
5. Display the highest integer of the array
6. Display the lowest integer of the array
7. Display the closest int to zero
ex.
String input: a97r2-5x1-1
Array: [9,7,2,-5,1,-1]
Length of String: 11
Length of Array: 6
Highest int = 9
Lowest int = -5
Int Closest to zero= 1(if the there are two int closest to zero like -1 and 1, it should be the negative)
here is my source code pero libog ko, pwede patabang? TIA!:weep:
Code:
import java.util.Scanner;
import java.util.*;
import javax.swing.*;
public class Prelim3
{
public static void main(String args[])
{
int highestInt = 0, lowestInt =0;
Scanner input = new Scanner(System.in);
System.out.println("String input: ");
String inputString = input.nextLine();
int i =0, minus=0;
String numbers = "[", forNumbersArray= "", forNumbersArrayLength ="";
char inputStringArray [] = inputString.toCharArray();
for(int x = 0; x<inputStringArray.length; x++)
{
if(Character.isDigit(inputStringArray[x]))
{
if(x==0)
numbers += inputStringArray[x];
else
numbers += ","+ inputStringArray[x];
forNumbersArray += inputStringArray[x];
forNumbersArrayLength +=inputStringArray[x];
}
else if(inputStringArray[x]== '-')
{
if(x==0)
numbers += "-"+inputStringArray[x+1];
else
numbers += ","+"-"+inputStringArray[x+1];
forNumbersArray +="-"+ inputStringArray[x+1];
forNumbersArrayLength +=inputStringArray[x+1];
x++; //x++;
}
else{}
}
System.out.println("array :"+numbers+"]");
System.out.println("Length of original String: "+inputStringArray.length);
char numbersArrayLength [] = forNumbersArrayLength.toCharArray();
char numbersArray [] = forNumbersArray.toCharArray();
System.out.println("Length of array: "+numbersArrayLength.length);
//System.out.println("length katong taas: "+numbersArray.length);
//DRI MAGSUGOD ANG PROBLEMA
//=================================================================
/* ******tang.tanga lng comment***
String theNumbers [] = new String [numbersArray.length];
for(int x = 0; x<inputStringArray.length; x++)
{
if(numbersArray[x]== '-')
{
theNumbers [i] = "-"+numbersArray[x+1];
x++; //x++;
}
else
{
theNumbers [i] = numbersArray[x]+"";
}
i++;
}
for(int x = 0; x<theNumbers.length;x++)
{
System.out.println("theNumbers ["+x+"]= "+theNumbers[x]);
}
int theNumbersConverted [] = new int [theNumbers.length];
for(int x=0; x<theNumbersConverted.length;x++)
{
theNumbersConverted[x] = Integer.parseInt(theNumbers[x]);//problema sad ni
/nganu di ma converte ang array na String into array int? sakto man ta syntax
}
for(int x = 0; x<theNumbersConverted.length;x++)
{
if(highestInt<theNumbersConverted[x])
highestInt = theNumbersConverted[x];
else
highestInt = highestInt;
}
System.out.println("The highest int: "+highestInt);
*
*/
}
}