This is my code so far:
public static void main (String[] args)
{
System.out.print("\f");
int num1 =0;
int totalp=0;
int totaln=0;
int avgp=0;
int avgn=0;
int greaterp=0;
int greatern=0;
int loop1=1;
int amountp=0;
int amountn=0;
int castsquaredp=0;
int castcubedp=0;
int castsquaredn=0;
int castcubedn=0;
Scanner scan = new Scanner (System.in);
System.out.println("\t\t\t"+"Positive"+"\t\t\t"+"Negative");
while(loop1!=0){
System.out.println("Enter Number: ");
num1=scan.nextInt();
if (num1>0)
{
totalp=totalp+num1;
amountp=amountp+1;
System.out.println("\t\t\t"+num1);
}
else if(num1<0)
{
totaln=totaln+num1;
amountn=amountn+1;
}
else if(num1==0)
{System.out.println("Cannot accept zeros Re-enter");
num1=scan.nextInt();
System.out.println("\t\t\t\t\t"+num1);
}
if (num1>0&&num1>greaterp)
{ greaterp=num1; }
if (num1<0&&num1<Math.abs(greatern))
{greatern=num1; }
System.out.print("Press 0 to exit/Press any integer to continue ");
loop1=scan.nextInt();
}
double squaredp =(int) Math.pow(greaterp,2);
double cubedp =(int) Math.pow(greaterp,3);
double squaredn= (int)Math.pow(greatern,2);
double cubedn=(int) Math.pow(greatern,3);
castsquaredp=(int)squaredp;
castcubedp=(int)cubedp;
castsquaredn=(int)squaredn;
castcubedn=(int)cubedn;
if (totalp>0)
avgp=totalp/amountp;
if (totaln>0)
avgn=Math.abs(totaln)/amountn;
System.out.println("The total positive integer values are: "+totalp);
System.out.println("The total negative integer values are: "+totaln);
System.out.println("The positive values average is : "+avgp);
System.out.println("The negative values average is : "+avgn);
System.out.println("The largest positive value is: "+greaterp+" This value squared "+castsquaredp+" This value cubed "+castcubedp);
System.out.println("The largest negative value is: "+greatern+" This value squared "+castsquaredn+" This value cubed "+castcubedn);
}
My question for you guys: Is it posssible to print two columns that organize the respective values without the use of an Array/ArrayList?
Thanks

New Topic/Question
Reply



MultiQuote




|